“使用CSOM指定的对象不属于列表”错误(“The object specified does not belong to a list” error using CSOM)

编程入门 行业动态 更新时间:2024-10-27 20:37:36
“使用CSOM指定的对象不属于列表”错误(“The object specified does not belong to a list” error using CSOM)

我试图在c#中使用.NET CSOM在线获取Sharepoint上的文件的父列表。 当我从一个独立的c#app测试它时,下面的代码工作正常。

但是当我通过c ++中的com interop调用完全相同的方法时,使用相同的参数,我得到一个异常,“指定的对象不属于列表”。 ExecuteQuery()之后抛出异常

但我知道它确实如此,如果我在一个独立的c#中使用完全相同的URL“/ sites / develop_apps / Shared Documents / subway / heynow(000640-9-9-2016 9-53-31 AM).PDF”调用该方法应用程序,我也不例外。 并且“GetFileByServerRelativeUrl”似乎工作正常。 无论如何它都不会抛出异常。

我读过有关类似错误的文章,他们似乎与网址有关。 但我无法理解为什么同一个参数在一个上下文中工作而不是另一个上下文。

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

Fiddler跟踪错误显示。

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

I am trying to get the parent list of a file on Sharepoint online with .NET CSOM in c#. The code below works fine when I test it from a standalone c# app.

But when I call the exact same method via a com interop in c++, with the same parameters, I get an exception, "the specified object does not belong to a list". Exception is thrown after the ExecuteQuery()

But I KNOW it does, If I call the method with the exact same URL "/sites/develop_apps/Shared Documents/subway/heynow(000640-9-9-2016 9-53-31 AM).PDF" in a standalone c# app, I get no exception. And the "GetFileByServerRelativeUrl" seems to be working fine. It doesn't throw an exception anyway.

I've read articles about similar errors and they seem to have something to do with the url possibly. But I can't understand why the same params work in one context but not another.

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

Fiddler trace of the error shows.

{ "SchemaVersion":"15.0.0.0","LibraryVersion":"16.0.5701.1202","ErrorInfo":{ "ErrorMessage":"The object specified does not belong to a list.","ErrorValue":null,"TraceCorrelationId":"c616a29d-90ab-3000-b1de-17538058f3e4","ErrorCode":-2146232832,"ErrorTypeName":"Microsoft.SharePoint.SPException" },"TraceCorrelationId":"c616a29d-90ab-3000-b1de-17538058f3e4"

最满意答案

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

我的测试工作有一个“ https://mysite.sharepoint.com/sites/develop_apps/ ”的网址。

我的生产测试失败了“ https://mysite.sharepoint.com ”

我在“ https://mysite.sharepoint.com/sites/develop_apps/ ”的库中进行了所有列表操作

我想在对列表进行工作时,在创建关于url的clientContext时需要更具体。

By comparing the ClientContext.Url fields of the working app and failing production test, I noticed that the urls were different.

My test that was working had a url of "https://mysite.sharepoint.com/sites/develop_apps/" .

My production test that's failing its "https://mysite.sharepoint.com"

and I was doing all my list manipulation in a library off of "https://mysite.sharepoint.com/sites/develop_apps/"

I guess when doing work against lists, you need to be more specific when creating your clientContext in regards to the url.

更多推荐

ExecuteQuery,GetFileByServerRelativeUrl,电脑培训,计算机培训,IT培训"/> <meta

本文发布于:2023-08-07 06:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463179.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不属于   对象   错误   列表   CSOM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!