Unable to get a driveitem of a file url from graph

%3CLINGO-SUB%20id%3D%22lingo-sub-2596151%22%20slang%3D%22en-US%22%3EUnable%20to%20get%20a%20driveitem%20of%20a%20file%20url%20from%20graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2596151%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%3C%2FP%3E%3CP%3EI%20try%20to%20send%20a%20rest%20api%20call%20with%20HttpProvider%20to%20get%20a%20driveitem%20of%20a%20file%20url%20(SharePoint%20file).%20I%20used%20following%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Evar%20graphClient%20%3D%20GetAuthenticatedClient()%3B%3C%2FP%3E%3CP%3Estring%20base64Value%3DSystem.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileUrl))%3B%3CBR%20%2F%3Estring%20encodedUrl%3D%22u!%22%20%2B%20base64Value.TrimEnd('%3D').Replace('%2F'%2C%20'_').Replace('%2B'%2C%20'-')%3B%3CBR%20%2F%3Evar%20requestURL%3DgraphClient.BaseUrl%20%2B%20%22%2Fshares%2F%22%20%2B%20encodedUrl%20%2B%20%22%2Fdriveitem%2Fcontent%22%3B%3CBR%20%2F%3EHttpRequestMessage%20message%3Dnew%20HttpRequestMessage(HttpMethod.Get%2CrequestURL)%3B%3CBR%20%2F%3Eawait%20graphClient.AuthenticationProvider.AuthenticateRequestAsync(message)%3B%3C%2FP%3E%3CP%3EHttpResponseMessage%20sharedDriveItem%3Dawait%20graphClient.HttpProvider.SendAsync(message)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20SendAsync%20I%20get%20an%20error%3A%3C%2FP%3E%3CP%3ESystem.NullReferenceException%3CBR%20%2F%3EHResult%3D0x80004003%3CBR%20%2F%3EMessage%3DObject%20reference%20not%20set%20to%20an%20instance%20of%20an%20object.%3CBR%20%2F%3ESource%3DMicrosoft.Graph.Core%3CBR%20%2F%3EStackTrace%3A%3CBR%20%2F%3Eat%20Microsoft.Graph.HttpProvider.%3CSENDASYNC%3Ed__18.MoveNext()%3CBR%20%2F%3Eat%20System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()%3CBR%20%2F%3Eat%20System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task%20task)%3CBR%20%2F%3Eat%20System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task%20task)%3C%2FSENDASYNC%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20idea%20about%20that%20problem%3F%3C%2FP%3E%3CP%3EBest%2C%20Harald%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2596151%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

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

0 Replies