我必须使用 CSOM 打印共享点站点下的子网站列表。我使用了这段代码和我的服务器凭据,但我在 foreach 循环的第二行进入了一个无限循环。这条线是
getSubWebs(新路径);
static string mainpath = "http://triad102:1001";
static void Main(string[] args)
{
getSubWebs(mainpath);
Console.Read();
}
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)
{
}
}
必须进行哪些代码更改才能检索子网站?