title: How to loop through all webs and sub webs of a SharePoint Web
body: <p>I am trying to loop through all webs and subs-webs of those webs under a web.</p>
  
  <p>My Parent web </p>
  
  <p><a href="http://EXAMPLE.com/parentweb" rel="nofollow">http://EXAMPLE.com/parentweb</a> (This is a sub site not a root web)</p>
  
  <p>sub webs
  <a href="http://example.com/parentweb/subweb" rel="nofollow">http://example.com/parentweb/subweb</a> ( This is one of the sub web which may or may not have sub webs)</p>
  
  <p>The only thing i tried is go to the site collection and loop throug all webs which is much longer process because i know the only sub site that needs to be checked. my site collection has multiple sub sites. i don't want to loop through all subs sites.</p>
  
  <p>This code works but it takes so much of time and it loops through all subsites which don't need to be checked </p>
  
  <pre><code>     using(SPSite site = new SPSite(“http://myserver/mysitecol”) 
             { 
                 foreach(SPWeb web in site.AllWebs) 
                 {
                 }
             } 
  </code></pre>