如何将文档从 Sharepoint 文档库返回给用户?
我正在从 Sharepoint 库检索文档列表。假设我的任务是向用户检索该列表中的第一个文档,以便他可以打开 docx 文件。我该如何去做呢?
更复杂的是共享点服务器位于另一个域。我正在开发的 Web 项目将向客户展示文档,但不会公开对共享点服务器的直接访问。
ClientContext clientContext = new ClientContext(URL);
List list = clientContext.Web.Lists.GetByTitle("My Documents");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = XML;
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(
listItems,
items => items.Include(item => item["FileRef"]));
clientContext.ExecuteQuery();
// return this file to the user
// listItems[0];
I am retrieving a document list from a Sharepoint library. Let's say my task is to retrieve the very first document in that list to the user so he can open a docx file. How do I go about doing that?
A further complication is that the sharepoint server is located on another domain. The web project that I am working on will surface the documents to the customer, but not expose direct access to the sharepoint server.
ClientContext clientContext = new ClientContext(URL);
List list = clientContext.Web.Lists.GetByTitle("My Documents");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = XML;
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(
listItems,
items => items.Include(item => item["FileRef"]));
clientContext.ExecuteQuery();
// return this file to the user
// listItems[0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以根据此查询的结果创建“A”元素,以便用户只需单击包含项目完整路径的链接(这大约是常规 SharePoint 列表的呈现方式)。
You can create "A" element based on result of this query so user can simply click on the link with full path to the item (this is approximately how regular SharePoint lists are rendered).
该解决方案的执行摘要如下。生成锚标记时,请包含来自 FileRef 字段的信息,您的文档应为其提供值。这是您稍后将使用的参考字段。
您致电时将使用该参考
The executive summary of the solution is as follows. When producing the anchor tags, include information from the FileRef field which your document should have a value for. This is a reference field that you will use later.
you will use the reference when you call