我正在尝试使用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();
答案 0 :(得分:1)
我现在正在移动设备上,因此我无法轻松为您测试此内容,但我相信您在加载context.ExecuteQuery()
后也需要AssetList
。
这将使您的来源:
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();
如果情况不是这样,请告诉我,我会启动一个项目,我已经在桌面上做了类似的事情。