I need to retrieve subsites that user has access using Client Object Model.
Here's what I've got:
NetworkCredential credential = new NetworkCredential(user, pwd, domain);
ClientContext clientContext = new ClientContext(string.Format("http://{0}:{1}/", server, port));
clientContext.Credentials = credential;
Web oWebsite = clientContext.Web;
clientContext.Load(oWebsite, website => website.Webs, website => website.Title);
clientContext.ExecuteQuery();
infos = new List<Infos>();
Infos info = null;
for (int i = 0; i != oWebsite.Webs.Count; i++)
{
info = new Infos();
info.SubSite = oWebsite.Webs[i].Title;
info.UrlSubSite = oWebsite.Webs[i].ServerRelativeUrl;
ListCollection lists = oWebsite.Webs[i].Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
foreach (var list in lists)
{
Lists myList = new Lists();
myList.Title = list.Title;
info.Listas.Add(myList);
}
infos.Add(info);
}
var query = from Infos i in infos
select i.SubSite;
return query.ToList();
}
catch(Exception ex)
{
throw ex;
}
return null;
}
=====
Using this code, I'm getting an 403 forbidden error. My client user doesn't have access on the root site (that I`m using in ClientContext constructor). But he has under some subsites. I need to get the subsites that he has access (just list them all), using Client Object Model.
Is there another way?
getSubwebsForCurrentUser
instead ofWebs
: msdn.microsoft.com/en-us/library/ee658739 – Rawling