【问题标题】:Unable to read Sharepoint List?无法读取共享点列表?
【发布时间】:2022-10-14 12:50:20
【问题描述】:

我们在 SharePoint 中有两个列表,它们被用作文件的主/元信息。我想使用 C# 列出这些列表的内容,但无法做到。

C# 代码引发错误并要求提供 SharePoint.intl 文件。我无法找到此文件。谁能建议,如何阅读 C# 中的 SharePoint 列表?

示例代码如下:

    static void Main(string[] args)
    {
        SPSite oSpSite = new SPSite("https://xxxxx.sharepoint.com/sites/MHLanding/");

        SPWeb oSPWeb = oSpSite.OpenWeb();

        SPList oSpList = oSPWeb.Lists["PermissionMatrix"];

        SPListItemCollection oSpListCln = oSpList.Items;

        foreach (SPListItem item in oSpListCln)
        {
            Console.WriteLine(item["SiteWorker"] + "\n");
        }

    }

【问题讨论】:

  • 它在构建或运行时失败?如果是运行时,哪一行?我在您的示例中没有看到身份验证代码。您只是发布部分代码吗?此外,您应该将 spsite 和 spweb 变量作为最佳实践代码。
  • 构建失败。你能分享读取共享点列表的代码片段吗?不确定是否遗漏了什么(参考 DLL 或 ???)

标签: c# list sharepoint


【解决方案1】:

工作以下解决方案:

// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("https://{site_url}");

// Assume the web has a list named "Announcements".
List announcementsList = context.Web.Lists.GetByTitle("Announcements");

// This creates a CamlQuery that has a RowLimit of 100, and also specifies     Scope="RecursiveAll"
 // so that it grabs all list items, regardless of the folder they are in.
 CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
 ListItemCollection items = announcementsList.GetItems(query);

// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(items);
context.ExecuteQuery();
foreach (ListItem listItem in items)
{
  // We have all the list item data. For example, Title.
  label1.Text = label1.Text + ", " + listItem["Title"];
}

【讨论】:

    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多