Joachim
Joachim

Reputation: 39

Microsoft Graph Content return null

I am trying to retrieve the content of my word document stored in my company SharePoint. The code is as follows:

GraphServiceClient graphClient = new GraphServiceClient(authProvider);
DriveItem document = await graphClient.Sites[_siteId].Drive.Items[remoteId].Request().GetAsync();
DocumentDTO dto = new DocumentDTO { Content = document.Content };

The dto has accessed the other information contained in the DriveItem such as Id and Name, but I don't understand why I can't access the content.

Looking for any possible help :-) Thanks

Upvotes: 1

Views: 1691

Answers (2)

Joachim
Joachim

Reputation: 39

I end up doing this to retrieve my content in Stream.

GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var document = await graphClient.Sites[_siteId].Drive.Items[remoteId].Request().GetAsync();
var url = document.AdditionalData["@microsoft.graph.downloadUrl"].ToString();

HttpClient http = new HttpClient();
var response = await http.GetAsync(url);
var content = await response.Content.ReadAsStreamAsync();

Upvotes: 2

Eastman
Eastman

Reputation: 368

If you look at the example response in the docs, the content is not returned when you make call as you have done in your example.

To get the content you would need to make a different/separate request as shown here.

Therefore, your code should look like something like this to get the content.


GraphServiceClient graphClient = new GraphServiceClient(authProvider);
Stream content = await graphClient.Sites[_siteId].Drive.Items[remoteId].Content.Request().GetAsync();
DocumentDTO dto = new DocumentDTO { Content = content  };

Upvotes: 2

Related Questions