1.8.07

Sharepoint: The object specified does not belong to a list

I had a problem this morning, with a custom control that I am using in PublishingPages and admin pages in the _layouts folder.
The control looks for some custom properties in the current pages ParentFolder. However when checking the SPFile.ParentFolder.Item property in a page located in _layouts it throws an exception - "The object specified does not belong to a list".
My first thought was to check for SPFile.ParentFolder.Item != null, but that didn't work. However by setting a break point I discoverd that folders in the _layouts directory don't exist!

So use: if(SPFolder.Exists) {}

No comments: