";已经存在“;使用CSOM获取SharePoint 2013库项目时引发异常

本文关键字:项目 2013 异常 SharePoint CSOM quot 存在 使用 获取 | 更新日期: 2023-09-27 18:00:44

我正在尝试使用C#中的CSOM从SharePoint 2013视频资产库中检索所有项目。当我运行控制台应用程序时,我偶尔会收到以下错误:

Microsoft.SharePoint.Client.ServerException: A list, survey, discussion board, or document library with the specified title already exists in this Web site.  Please choose another title.

我搜索了错误,但发现的问题是创建列表或更新项目。我只是想取回这些物品。该库在浏览器中加载很好。此外,我有一个网页,它运行与我的控制台应用程序相同的代码,并且不会引发异常。以下是引发异常的代码块:

ClientContext context = new ClientContext(SharePointURL);
                List AssetList = context.Web.Lists.GetByTitle(SharePointListTitle);
                context.Load(AssetList);
                CamlQuery query = CamlQuery.CreateAllItemsQuery();
                ListItemCollection items = AssetList.GetItems(query);
                //Retrieve all items in the ListItemCollection from List.GetItems(Query). 
                context.Load(items,
                    itms => itms.Include(
                        i => i["GUID"],
                        i => i["Title"],
                        i => i["FileLeafRef"],
                        i => i["FileRef"],
                        i => i["VideoSetDescription"],
                        i => i["Live_x0020_Date"],
                        i => i["Expiration_x0020_Date0"],
                        i => i["Is_x0020_Active"],
                        i => i["Tags"],
                        i => i["AlternateThumbnailUrl"]
                        )
                    );
                context.ExecuteQuery();

";已经存在“;使用CSOM获取SharePoint 2013库项目时引发异常

我现在在移动设备上,所以我不能很容易地为您测试,但我相信您也需要在加载AssetList后执行context.ExecuteQuery()

这将使你的来源:

ClientContext context = new ClientContext(SharePointURL);
List AssetList = context.Web.Lists.GetByTitle(SharePointListTitle);
context.Load(AssetList);
context.ExecuteQuery();
CamlQuery query = CamlQuery.CreateAllItemsQuery();
ListItemCollection items = AssetList.GetItems(query);
//Retrieve all items in the ListItemCollection from List.GetItems(Query). 
context.Load(items,
    itms => itms.Include(
        i => i["GUID"],
        i => i["Title"],
        i => i["FileLeafRef"],
        i => i["FileRef"],
        i => i["VideoSetDescription"],
        i => i["Live_x0020_Date"],
        i => i["Expiration_x0020_Date0"],
        i => i["Is_x0020_Active"],
        i => i["Tags"],
        i => i["AlternateThumbnailUrl"]
        )
    );
context.ExecuteQuery();

如果不是这样的话,请告诉我,我会在桌面上调出一个我做过类似事情的项目。