Pull the information about all the subsites under a root site collection
Here I am giving a sample code which will iterate all the subsites of a root site collection and display some information.
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Microsoft.SharePoint;
5:
6: namespace SubSiteReport
7: {
8: class Program
9: {
10: static void Main(string[] args)
11: {
12: Console.WriteLine("Enter your site collection URL :");
13: string strUrl = Console.ReadLine();
14:
15: using (SPSite oSite = new SPSite(strUrl))
16: {
17: using (SPWeb oRootWeb = oSite.OpenWeb())
18: {
19: SPWebCollection oWebs = oRootWeb.Webs;
20: if (oWebs.Count == 0)
21: Console.WriteLine("No subsites !");
22: else
23: GetData(oWebs);
24: }
25: }
26:
27: Console.ReadLine();
28: }
29:
30: static void GetData(SPWebCollection oWebs)
31: {
32: foreach (SPWeb oWeb in oWebs)
33: {
34: Console.WriteLine("Name :" + oWeb.Name);
35: Console.WriteLine("Title :" + oWeb.Title);
36: Console.WriteLine("URL :" + oWeb.Url);
37: Console.WriteLine("Last modified Date :" + oWeb.LastItemModifiedDate.ToString());
38: Console.WriteLine("Created By : Name: " + oWeb.Author.Name + " Login Name: " + oWeb.Author.LoginName);
39: Console.WriteLine("Created Date :" + oWeb.Created.ToString());
40: Console.WriteLine("******************************************");
41:
42: if (oWeb.Webs.Count > 0)
43: {
44: GetData(oWeb.Webs);
45: }
46: }
47:
48: }
49: }
50: }
Comments
Anonymous
October 28, 2008
PingBack from http://blog.a-foton.ru/index.php/2008/10/29/pull-the-information-about-all-the-subsites-under-a-root-site-collection/Anonymous
May 08, 2009
thnx Sowmya for the above code. I was looking for the similar kind of code. Thnx prasadwtAnonymous
May 08, 2009
The comment has been removed