public async Async.Task OneNotePagePreview() { try { // Get a page of OneNote pages IOnenoteSectionPagesCollectionPage pageCollection = await graphClient.Me .Onenote .Sections[firstSectionID] .Pages .Request() .GetAsync(); // Get a handle to the first section. string pageId = pageCollection[0].Id; // URL to update a page. https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages/{id}/preview OnenotePagePreview pagePreview = await graphClient.Me .Onenote .Pages[pageId] .Preview() .Request() .GetAsync(); Assert.IsNotNull(pagePreview, "OnenotePagePreview object is null. This shouldn't be null. Check your request."); } catch (Microsoft.Graph.ServiceException e) { Assert.Fail("Error code: {0}", e.Error.Code); } catch (Exception e) { Assert.Fail("Error code: {0}", e.Message); } }
public async Task OneNotePagePreview() { try { // Get a page of OneNote pages IOnenoteSectionPagesCollectionPage pageCollection = await graphClient.Me .Onenote .Sections[firstSectionID] .Pages .Request() .GetAsync(); // Get a handle to the first section. string pageId = pageCollection[0].Id; // URL to update a page. https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages/{id}/preview OnenotePagePreview pagePreview = await graphClient.Me .Onenote .Pages[pageId] .Preview() .Request() .GetAsync(); Assert.NotNull(pagePreview); } catch (Microsoft.Graph.ServiceException e) { Assert.True(false, $"Error code: {e.Error.Code}"); } catch (Exception e) { Assert.True(false, $"Error code: {e.Message}"); } }
public async Task FixBrokenLinks(int selectedNotebookNumber) { logger.Info("Processing the Notebook " + notebookMap[selectedNotebookNumber].DisplayName); INotebookSectionsCollectionPage mySections = await GetSections(notebookMap[selectedNotebookNumber]); foreach (OnenoteSection section in mySections) { logger.Info("Processing Section " + section.DisplayName); IOnenoteSectionPagesCollectionPage pageList = await GetPagesInSection(section); foreach (OnenotePage page in pageList) { logger.Info("Processing Page " + page.Title + " in the Section " + section.DisplayName); await FixBrokenLinksInPage(page); } } }
public async Async.Task OneNoteUpdatePage() { try { // Get a page of OneNote pages IOnenoteSectionPagesCollectionPage pageCollection = await graphClient.Me.Onenote.Sections[firstSectionID].Pages.Request().GetAsync(); // Get a handle to the first section. string pageId = pageCollection[0].Id; // URL to update a page. https://graph.microsoft.com/v1.0/me/onenote/sections/{id}/pages/{id}/content var requestUrl = graphClient.Me.Onenote.Pages[pageId].Content.Request().RequestUrl; // Create the patch command to update thebody of the OneNote page. OnenotePatchContentCommand updateBodyCommand = new OnenotePatchContentCommand() { Action = OnenotePatchActionType.Append, Target = "body", Content = @"<table><tr><td><p><b>Brazil</b></p></td><td><p>Germany</p></td></tr> <tr><td><p>France</p></td><td><p><b>Italy</b></p></td></tr> <tr><td><p>Netherlands</p></td><td><p><b>Spain</b></p></td></tr> <tr><td><p>Argentina</p></td><td><p><b>Germany</b></p></td></tr> </table>", Position = OnenotePatchInsertPosition.After }; List <OnenotePatchContentCommand> commands = new List <OnenotePatchContentCommand>(); commands.Add(updateBodyCommand); // Create the request message. HttpRequestMessage hrm = new HttpRequestMessage(new HttpMethod("PATCH"), requestUrl); // Serialize the OnenotePatchContentCommand object and add to the request. string updateBodyCommandString = graphClient.HttpProvider.Serializer.SerializeObject(commands); hrm.Content = new StringContent(updateBodyCommandString); hrm.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // Send the request and get the response. HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(hrm); // We get a 204 No Content. if (response.IsSuccessStatusCode) { Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.NoContent, $"Expected: 204 No Content, Actual: {response.StatusCode}"); } else { throw new ServiceException( new Error { Code = response.StatusCode.ToString(), Message = await response.Content.ReadAsStringAsync() }); } } catch (Microsoft.Graph.ServiceException e) { Assert.Fail("Error code: {0}", e.Error.Code); } catch (Exception e) { Assert.Fail("Error code: {0}", e.Message); } }