[英]How to create a sharepoint link for a onenote section, using Graph API
I am using Graph API in.Net to access a OneNote notebook in a client's Sharepoint.我在 .Net 中使用 Graph API 来访问客户端 Sharepoint 中的 OneNote 笔记本。 So far, so good.到目前为止,一切都很好。 I can access the notebook, and loop through sections.我可以访问笔记本,并循环浏览各个部分。
However, the requirement is for me to return a sharepoint link for a notebook section, in the form https://companyname.sharepoint.com/sites/NotebookName/_layouts/15/Doc.aspx?sourcedoc={7636j9a7-2364-4b40-8h33-c6ba539f98cd}&action=edit&wd=target%28SectionName.one%7C5jd216c9-bcn4-43e2-896e-86p2b765a415%2F%29&wdorigin=717但是,要求我以https://companyname.sharepoint.com/sites/NotebookName/_layouts/15/Doc.aspx?sourcedoc={7636j9a7-2364-4b40的形式返回笔记本部分的共享点链接-8h33-c6ba539f98cd}&action=edit&wd=target%28SectionName.one%7C5jd216c9-bcn4-43e2-896e-86p2b765a415%2F%29&wdorigin=717
Using Graph API, I get a URL like this one: https://graph.microsoft.com/v1.0/sites/companyname.sharepoint.com,81ba2d09-8378-5d84-b365-9gd9bb83f9c3,f5bd4b76-7796-4354-8d53-07d5dbb843f6/onenote/sections/1-328ab290-37bd-4495-9009-2437bef11d54/pages使用 Graph API,我得到了这样一个 URL: https ://graph.microsoft.com/v1.0/sites/companyname.sharepoint.com,81ba2d09-8378-5d84-b365-9gd9bb83f9c3,f5bd4b76-7796-4354- 8d53-07d5dbb843f6/onenote/sections/1-328ab290-37bd-4495-9009-2437bef11d54/pages
I am unable to get from the graph-api url to the sharepoint url.我无法从 graph-api url 获取共享点 url。 Is it possible to construct a sharepoint url like the one above using Graph API?是否可以使用 Graph API 构建像上面那样的共享点 url?
Here is the code I'm using:这是我正在使用的代码:
` `
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var site = await graphClient.Sites.GetByPath("/sites/NoteBookName", "companyname.sharepoint.com")
.Request()
.GetAsync();
var notebooks = await graphClient.Sites[site.Id]
.Onenote
.Notebooks
.Request()
.GetAsync();
var notebook = notebooks.Where(x => x.Id == "1-abcdefgh-2364-4b40-8e33-c6ba539f98cd").FirstOrDefault();
if (notebook != null)
{
var sections = await graphClient.Sites[site.Id]
.Onenote
.Notebooks[notebook.Id]
.Sections
.Request()
.GetAsync();
var firstSection = sections.FirstOrDefault();
if (firstSection != null)
{
Console.WriteLine(firstSection.Self);
}
}
` `
Thanks, Dermot谢谢,德莫特
I have drilled down into the notebook as per the code above, but am unable to construct a sharepoint URL.我已按照上面的代码深入到笔记本中,但无法构建共享点 URL。
I found the answer to this, and it was a lot more straightforward than I expected.我找到了这个问题的答案,而且比我预期的要简单得多。 The Sharepoint URL is stored in the section object, in Links.OneNoteWebUrl. Sharepoint URL 存储在 Links.OneNoteWebUrl 中的部分对象中。
Hopefully this saves someone else from all the head-scratching I did over the past few weeks.希望这能让其他人免于我在过去几周所做的所有令人头疼的事情。
var sections = await graphClient.Sites[site.Id]
.Onenote
.Notebooks[notebook.Id]
.Sections
.Request()
.GetAsync();
foreach (var section in sections)
{
Console.WriteLine(section.DisplayName);
Console.WriteLine(section.Links.OneNoteWebUrl.Href);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.