使用 CSOM "The object specified does not belong to a list"错误



我试图在c#中使用。net CSOM在线获取Sharepoint上文件的父列表。当我从一个独立的c#应用程序中测试它时,下面的代码运行良好。

但是当我在c++中通过com互操作调用完全相同的方法时,使用相同的参数,我得到一个异常,"指定的对象不属于列表"。在ExecuteQuery()

之后抛出异常。如果我在一个独立的c#应用程序中使用完全相同的URL /sites/develop_apps/Shared Documents/subway/heynow(000640-9-9-2016 9-53-31 AM).PDF调用该方法,我不会得到例外。GetFileByServerRelativeUrl"看起来还行。它不会抛出异常。

我读过关于类似错误的文章,它们似乎可能与url有关。但是我不明白为什么相同的参数在一个上下文中可以工作,而在另一个上下文中却不行。

 Microsoft.SharePoint.Client.File thisFile =m_clientContext.Web.GetFileByServerRelativeUrl(fileRelativeUrl);
ListItem item = thisFile.ListItemAllFields;
m_clientContext.Load(item.ParentList);
m_clientContext.ExecuteQuery();

提琴手的错误显示。

{"SchemaVersion"15.0.0.0"LibraryVersion":"16.0.5701.1202","ErrorInfo": {ErrorMessage":"指定的对象不属于列表!","ErrorValue" null,"TraceCorrelationId":"c616a29d ab - 90 - 3000 - b1de - 17538058 - f3e4"ErrorCode": -2146232832,"ErrorTypeName":"Microsoft.SharePoint.SPException"},"TraceCorrelationId"c616a29d ab - 90 - 3000 - b1de - 17538058 - f3e4"

通过比较工作应用程序的Url字段和失败的生产测试,我注意到Url是不同的。

我的测试工作有一个url的"https://mysite.sharepoint.com/sites/develop_apps/"。

我的生产测试失败了,它的"https://mysite.sharepoint.com"

我在"https://mysite.sharepoint.com/sites/develop_apps/"

的库中做所有的列表操作

我猜在做针对列表的工作时,你需要在创建关于url的clientContext时更具体。

相关内容

最新更新