Wednesday, 4 July 2012

Get all sites that user has access with SharePoint 2010 using GetSubwebsForCurrentUser()


GetSubwebsForCurrentUser() is a very useful method when you need to retrieve all the sites \subsites that use has access to.
Let me put it other way, If you do not run a program under elevent context and loop though all the webs in a site it would present you with the following error


"Access denied. You do not have permission to perform this action or access this resource."


You can however useGetSubwebsForCurrentUser() which would only get you all the sites current user has access to.

Here is a client object model example

WebCollection result = oWebsite.GetSubwebsForCurrentUser(new SubwebQuery()); clientContext.Load(result, n => n.Include(o => o.Title));
clientContext.ExecuteQuery();

Ads by Google

No comments:

Post a Comment