我有一个sharepoint网络应用程序,有两个子网站" test1"和" test2"。
地址是下一个:
http://www05:48042/sites/test1
http://www05:48042/sites/test2
var context = new ClientContext(string.Format("http://{0}", "www05:48042"));
context.Credentials = new NetworkCredential(credentials.Login,
credentials.Password);
var sites = context.Web.Webs;
context.Load(sites);
context.ExecuteQuery();
登录和密码正确无误。但是,我总是在网上获得一个空集合,但应该至少得到2个元素。我究竟做错了什么?有什么建议吗?
答案 0 :(得分:0)
请使用以下代码段:
public static void getSubWebs(string path)
{
try
{
ClientContext clientContext = new ClientContext(path);
Web oWebsite = clientContext.Web;
clientContext.Load(oWebsite, website => website.Webs, website => website.Title);
clientContext.ExecuteQuery();
foreach (Web orWebsite in oWebsite.Webs)
{
string newpath = mainpath + orWebsite.ServerRelativeUrl;
getSubWebs(newpath);
Console.WriteLine(newpath + "\n" + orWebsite.Title);
}
}
catch (Exception ex)
{
}
}
static string mainpath = "http://sp:80/";
getSubWebs(mainpath);
Console.Read();