C# 为什么这段代码会导致无限循环?

C# 为什么这段代码会导致无限循环?,c#,timeout,sharepoint-2013,csom,request-timed-out,C#,Timeout,Sharepoint 2013,Csom,Request Timed Out,我必须使用CSOM打印sharepoint网站下的子网站列表。 我使用了这段代码和我的服务器凭据,但我进入了foreach循环第2行的无限循环中。 电话是 getSubWebs(newpath) 检索子网站需要进行哪些代码更改?您正在将子例程添加到变量mainpath static string mainpath = "http://triad102:1001"; public static void getSubWebs(string path) { try

我必须使用CSOM打印sharepoint网站下的子网站列表。 我使用了这段代码和我的服务器凭据,但我进入了foreach循环第2行的无限循环中。 电话是

getSubWebs(newpath)


检索子网站需要进行哪些代码更改?

您正在将子例程添加到变量mainpath

static string mainpath = "http://triad102:1001";

public static  void  getSubWebs(string path)
{          
    try
    {
        ...
        foreach (Web orWebsite in oWebsite.Webs)
        {
            string newpath = mainpath + orWebsite.ServerRelativeUrl; //<---- MISTAKE
            getSubWebs(newpath);
        }
    }
    catch (Exception ex)
    {          
    }           
}

您是否获得了一个
堆栈溢出异常
static string mainpath = "http://triad102:1001";

public static  void  getSubWebs(string path)
{          
    try
    {
        ...
        foreach (Web orWebsite in oWebsite.Webs)
        {
            string newpath = mainpath + orWebsite.ServerRelativeUrl; //<---- MISTAKE
            getSubWebs(newpath);
        }
    }
    catch (Exception ex)
    {          
    }           
}
static string mainpath = "http://triad102:1001";

public static  void  getSubWebs(string path)
{          
    try
    {
        ...
        foreach (Web orWebsite in oWebsite.Webs)
        {
            string newpath = path + orWebsite.ServerRelativeUrl; 
            getSubWebs(newpath);
        }
    }
    catch (Exception ex)
    {          
    }           
}