Reputation: 950
I'm swapping out my usage of the old OneDrive SDK to programmatically access the contents of OneNote in a UWP app, and I've begun using the Microsoft Graph for .NET SDK. One of the things I need to do is get a specific page's content. Currently, I'm attempting to do so like this:
await _graphClient.Me.Onenote.Pages
.Request()
.Filter("tolower(title) eq 'shopping list'")
.GetAsync();
...which works, and gets me all the pages in my notebook with the title of "shopping list". However, all of those pages have a null
Content
property, leaving me unable to get the HTML content of those pages. I can verify that at least one of these pages does, in fact, have content in the OneNote application.
I've read through the documentation for the SDK, and it appears that I should just be getting a Stream
back without any further action. Is there a step I'm missing, or am I using the API incorrectly?
Upvotes: 0
Views: 2089
Reputation: 950
It turns out that the SDK supports getting an individual page's Content directly, but the syntax to do so isn't very discoverable. It is:
Stream pageContent = await _graphClient.Me.Onenote.Pages[page.Id]
.Content // This could be omitted to retrieve every property on the page, presumably
.Request()
.GetAsync();
Turns out an IOnenotePagesCollectionRequestBuilder
returned by _graphClient.Me.Onenote.Pages
supports key-style indexing to retrieve a specific page. Totally unfindable with the default intellisense dropdown =/
Upvotes: 1
Reputation: 59328
Page content could be requested per single page, for example:
GET https://graph.microsoft.com/v1.0/me/onenote/pages/{page-id}/content
Per collection of pages content could be requested like this (via contentUrl
property of Page
resource):
var result = await graphClient.Me.Onenote.Pages.Request().GetAsync();
foreach (var page in result)
{
//download Page content
var message = new HttpRequestMessage(HttpMethod.Get, page.ContentUrl);
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message);
var response = await graphClient.HttpProvider.SendAsync(message);
var content = await response.Content.ReadAsStringAsync(); //get content as HTML
}
Upvotes: 1