如何构建/获取sharepoint文档的Office Web应用程序URL



我正试图为我的sharepoint文档获得正确的重定向URL,然后我可以使用它在iOS的WebView中打开文档。目前,我给出了文档的绝对URL,其中文档在WebView中呈现为PDF(图像/只读)。而我想重定向到办公室的web应用程序。现在我的问题是,我不知道如果URL的办公网络应用程序是我可以像附加/_layouts/15/WopiFrame.aspx构建的东西?sourcedoc= or是基于安装的自定义URL,我们需要调用一些Sharepoint API来告诉我们Wopi服务的基本URL是什么。

目前我正在传递URL,如- https://.sharepoint.com/Shared%20Documents/demo/demo.docx而我想传递URL - https://.sharepoint.com/_layouts/15/WopiFrame.aspx?sourcedoc=/Shared%20Documents/demo/demo.docx

期待帮助。提前感谢,Vishwesh

File f = clientContext.Web.GetFileByServerRelativeUrl("/sites/  /Shared%20Documents/Title.docx");
clientContext.Load(f);
clientContext.ExecuteQuery();
ClientResult<String> result = f.ListItemAllFields.GetWOPIFrameUrl(SPWOPIFrameAction.Edit);
clientContext.Load(f.ListItemAllFields);
clientContext.ExecuteQuery();

结果。Value包含一个URL,就像这样:http://sharep.xxx: 8080/网站/zxxx/_layouts/15/WopiFrame.aspx ? sourcedoc = % 2 fsites % 2 fzxxx % 2 fshared % 20文件% 2 ftitle % 2 edocx& action =编辑

如果你不想碰到sharepoint,你也可以从上面的页面中提取Office Web Apps的URL。

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;
// Assume we have these variables:
// ctx: A valid client context
// serverRelativeUrl: the URL of the document
File f = ctx.Web.GetFileByServerRelativeUrl (serverRelativeUrl);
result = f.ListItemAllFields.GetWOPIFrameUrl(SPWOPIFrameAction.Edit);
ctx.Load(f.ListItemAllFields);
ctx.ExecuteQuery();

这是建立在@thebitlic的答案之上的,这个答案肯定是银弹!然而,他或她正在对服务器进行两次调用。通过CSOM批处理的神奇功能,可以在一次往返中完成此操作,并且根本不需要返回File对象。

最新更新