[英]How to get subsites that a logged user has access in sharepoint 2010
我需要使用客戶端對象模型檢索用戶有權訪問的子站點。
這是我得到的:
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;
}
=====
使用此代碼,我收到403禁止錯誤 。 我的客戶用戶無權訪問根站點(我在ClientContext構造函數中使用的根站點)。 但是他有一些子站點。 我需要使用客戶端對象模型來獲取他有權訪問的子站點(只需列出所有子站點)。
還有另一種方法嗎?
ClientContext clientContext =
new ClientContext(string.Format("http://{0}:{1}/",
server,
port));
WebCollection webs = clientContext.Web.GetSubwebsForCurrentUser(null);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.