【问题标题】:C# Retrieve Document List From SharePoint 2013 Document LibraryC# 从 SharePoint 2013 文档库中检索文档列表
【发布时间】:2017-07-03 04:07:40
【问题描述】:

我想让这变得非常简单。我有一个全新的、全新的 asp.net C# web 表单,其背后的代码如下所示。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

我有一个 SharePoint 2013 网站,其中包含一个文档库,其中包含一些文档和几列元数据。

如何让它显示在网页上、每个文档的链接以及库中每个文档的列中的元数据。对于集成 SharePoint 和 ASP.Net 的任何工作,我都是超级新手。

请帮忙。

安迪

【问题讨论】:

    标签: c# sharepoint-2013


    【解决方案1】:

    Sharepoint 有 3 个您可以使用的 API。看看这里:https://msdn.microsoft.com/en-us/library/office/jj164060.aspx

    您可能希望通过 CSOM 库 (Microsoft.SharePoint.Client) 使用 client.svc 服务,因为它最容易启动和运行。不要使用旧的 asmx api,因为它已被弃用。还有第三种选择 - REST - 但它没有提供 CSOM 提供的所有功能。

    这里有一些显示基本知识的粗略代码。代码中没有涵盖许多细微差别(SharePoint 很复杂),因此您还需要在线查找一些其他信息。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint.Client;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected string SiteUrl = "http://mysite.mydomain.com/site";
        protected string LibraryName = "MyList";
    
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new ClientContext(SiteUrl);
            context.Load(context.Site);
            context.ExecuteQuery();
    
            var list = context.Web.Lists.GetByTitle(LibraryName);
    
            if (list == null)
            {
                throw new ArgumentException(string.Format("List with name '{0}' not found on site '{1}'", LibraryName, SiteUrl));
            }
    
            context.Load(list, l => l.RootFolder.ServerRelativeUrl);
            context.ExecuteQuery();
    
            // Empty query. You probably want to filter on something so
            // do a search on "CAML Query". Also watch out for SharePoint
            // List View Threshold which limits # of items that can be retrieved
            var camlQuery = @"<View Scope='All'><Query></Query></View>";
    
            var items = list.GetItems(camlQuery);
            context.Load(items, l => l.IncludeWithDefaultProperties(i => i.Folder, i => i.File, i => i.DisplayName)); 
            context.ExecuteQuery();
    
           // Url for first item
           var url = SiteUrl + "/" + LibraryName + "/" + items[0]["Title"]
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      相关资源
      最近更新 更多