Monday, April 18, 2011

The object specified does not belong to a list

I started getting the "The object specified does not belong to a list" error on a SharePoint site I migrated from 2007 to 2010. The code I "inherited" worked fine in 2007 but raised an error in 2010.

After some investigation, the problem ended up being that an SPFile was constructed in a parent web instead of the web in which the actual file resided using SPWeb.GetFile(url).

So to fix the problem, make sure you construct your SPFile object (using GetFile anyway) in the SPWeb in which the file resides.

eg. if the file lives here: \ParentSite\SubSite\Pages\Page.aspx, make sure the SPWeb you are using is "Subsite".

1 comment:

Howard said...

Thanks for this - it helped me. Cheers. Howard. http://spfarm.blogspot.com/