Question

How to get All Subwebs upto N Levels for Specified Web.

eg.

My Site url is...

"http://server/web1"

I need all subwebs upto N Levels for web1..

below line get all subwebs upto N Levels of sitecollection

SPWebCollection allwebcoll = spsite.AllWebs;

but i dont need all subwebs upto N Levels of site collection.

I need all subwebs upto N Levels for specified web.

Thanks...

Was it helpful?

Solution

if you want to recursive for specific SPWeb than

try this :

   SPWeb web = SPContext.Current.Web;
   recursive(web);

function for recursive :

 protected void recursive(SPWeb web)
    {
        string webTitle = web.Title;

        if (web.Webs.Count > 0)
        {
            foreach (SPWeb oweb in web.Webs)
            {
                recursive(oweb);
            }
        }

       if(web != null)
          web.Dispose();
    }       
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top