i have a requirement to loop all document libraries from sharpeoint server, however i failed at subsite of the subsite
first of all i use method below to get my SiteCollections
internal List<string> GetAllSite()
{
List<string> siteCollection = new List<string>();
try
{
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
SPServiceCollection services = SPFarm.Local.Services;
foreach (SPService curService in services)
{
if (curService is SPWebService)
{
SPWebService webService = (SPWebService)curService;
foreach (SPWebApplication webApp in webService.WebApplications)
{
foreach (SPSite sc in webApp.Sites)
{
try
{
siteCollection.Add(sc.Url);
Console.WriteLine("Do something with site at: {0}", sc.Url);
}
catch (Exception e)
{
Console.WriteLine("Exception occured: {0}\r\n{1}", e.Message, e.StackTrace);
}
}
}
}
}
});
}
catch (Exception ex)
{
throw;
}
return siteCollection;
}
after that i use the return sitecollection url to loop for subsite as below code
using (SPSite site = new SPSite(SiteCollectionUrl))
{
foreach (SPWeb web in site.AllWebs)
{
//i get the subsite url from here
}
}
right now here is my problem, as i mentioned earlier, i wanted to get subsite of the subsite, so i pass my subsite url to SPSite, however it will only loop SiteCollections instead of my subsites
foreach (SPWeb web in site.AllWebs) <-- i means here, over here will only loop my sitecollection item alhought i already pass my subsite url as parameters