简体   繁体   English

如何将文档从Sharepoint文档库返回给用户?

[英]How do I return a document from a Sharepoint Document library to the user?

I am retrieving a document list from a Sharepoint library. 我正在从Sharepoint库中检索文档列表。 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. 假设我的任务是向用户检索该列表中的第一个文档,以便他可以打开docx文件。 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. 我正在处理的Web项目会将文档显示给客户,但不会公开直接访问Sharepoint服务器。

    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];

您可以基于此查询的结果创建“ A”元素,以便用户只需单击具有该项目完整路径的链接即可(这大约是呈现常规SharePoint列表的方式)。

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. 生成锚标记时,请包含来自FileRef字段的信息,您的文档应为此值。 This is a reference field that you will use later. 这是一个参考字段,您将在以后使用。

you will use the reference when you call 致电时将使用参考

        FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, reference);

        Stream stream = fileInformation.Stream; 
        if (stream != null)
        {
            documentName = Path.GetFileName(reference);

            return new FileStreamResult(stream, "unknown")
            {
                FileDownloadName = documentName
            };
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Sharepoint 文档库下载 - Downloading from Sharepoint Document Library 从SharePoint文档库下载而无需用户登录 - Download from SharePoint Document Library without having user login 如何隐藏sharepoint文档库 - How to hide sharepoint document library 如何使用C#从SharePoint 2013文档库中删除用户权限 - How to remove user permissions from a SharePoint 2013 document library using c# 用户权限在库SharePoint 2010中添加文档 - user rights to add document in library SharePoint 2010 如何将文件上传到 sharepoint 中的文档库? - How do you upload a file to a document library in sharepoint? 如何代表其他用户关注 SharePoint 文档库 (SharePoint online) 中的文档 - How to Follow document from SharePoint document library (SharePoint online) on behalf of other users 如何应用SharePoint Web服务为文档返回ModifiedBy,TimeLastModified,UniqueID和FileType? - How do I apply SharePoint web service to return ModifiedBy, TimeLastModified, UniqueID and FileType for a document? 如何将文档库/库从一个Sharepoint服务器复制到另一个 - How to copy document library/libraries from one Sharepoint server to another 如何从 Sharepoint 文档库自动签出 Excel 电子表格、编辑电子表格并重新签入? - How can I automate the checkout of an excel spreadsheet from a sharepoint document library, edit the spreadsheet, and check it back in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM