Forum Discussion
Unable to get a driveitem of a file url from graph
Hi there
I try to send a rest api call with HttpProvider to get a driveitem of a file url (SharePoint file). I used following code:
var graphClient = GetAuthenticatedClient();
string base64Value=System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileUrl));
string encodedUrl="u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-');
var requestURL=graphClient.BaseUrl + "/shares/" + encodedUrl + "/driveitem/content";
HttpRequestMessage message=new HttpRequestMessage(HttpMethod.Get,requestURL);
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message);
HttpResponseMessage sharedDriveItem=await graphClient.HttpProvider.SendAsync(message);
On SendAsync I get an error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Graph.Core
StackTrace:
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Any idea about that problem?
Best, Harald