AllWebs Access Denied

SPSite MySite = new SPSite(Url_string);
SPWeb MyWeb = MySite.AllWebs[Web_string];
SPList MyPictureList = MyWeb.Lists[List_string];

this code will crash for anonymous users or those without enough permissions

instead do (which returns all but the root site):

SPSite MySite = new SPSite(Url_string);
SPWebCollection UserSites = MySite.OpenWeb().GetSubwebsForCurrentUser();
SPWeb MyWeb = UserSites[Web_string];
SPList MyPictureList = MyWeb.Lists[List_string];


or even better:

SPSite MySite = new SPSite(Url_string);
SPWeb MyWeb = MySite.OpenWeb(Web_string);
SPList MyPictureList = MyWeb.Lists[List_string];

Source
http://wssdevelopment.blogspot.com/2008/01/access-denied-when-using-spsiteallwebs.html

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Working around X-Frame-Options for iframes

Document ID not being generated