Wednesday, May 20, 2009

SharePoint Web-part dev problem - List does not exist

Problem:
I was working on a web-part with a custom ASPX file. It was working just fine for the root site of a site collection, but when testing it on a subsite it failed to load the ASPX file with the following exception:

List does not exist

The page you selected contains a list that does not exist. It may have been deleted by another user.

Solution:
There are few suggestions that didn't help me on the web. With the good old method - remove everything and check what's making the problem I found the perpetrator: in the ASPX page, I used SharePoint:FormattedStringWithListType, which caused the exception.

Using reflector I found that FormattedStringWithListType has a property 'List' which opens SPList with the current SPWeb context (list GUID is taken from the request parameter named 'List'). At this point I noticed that when the ASPX file is opened, it is done from the site collection level & not the sub site level.

From here there are few possible solutions:
*. Open the ASPX file from the subsite level (probably the best solution).
*. Don't use the class FormattedStringWithListType
*. Copy with reflector & fix the problem using SPSite.