如何构build/获取SharePoint文档的Office Web App URL

我正在尝试为我的SharePoint文档获取正确的redirectURL,然后我可以使用它在iOS的WebView中打开文档。 目前,我正在为文档在WebView内呈现为PDF(Image / Readonly)的文档提供绝对URL。 而我想redirect到办公室的webapp。 现在我的问题是我不知道如果办公室的Web应用程序的URL是我可以构造像附加/_layouts/15/WopiFrame.aspx?sourcedoc=或基于安装的URL定制,我们需要调用一些Sharepoint API将让我们知道Wopi服务的基本URL是什么。

目前我传递的url类似于 – https://.sharepoint.com/Shared%20Documents/demo/demo.docx而我想传递URL – https://.sharepoint.com/_layouts/15/WopiFrame.aspx? sourcedoc = /共享%20Documents /演示/ 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(); 

result.Value包含一个URL,如下所示: http ://sharep.xxx:8080/sites/zxxx/_layouts/15/WopiFrame.aspx?sourcedoc=%2Fsites%2Fzxxx%2FShared%20Documents%2FTitle%2Edocx&action=edit

另外,如果您不想打到共享点,则可以从上面的页面中提取摘录的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(); 

这是build立在@thebitlic的答案上,这是当然的银弹! 但是他或她正在对服务器进行两个调用。 通过CSOM批处理的奇迹,可以一次往返,不需要带回File对象。