Excel Way of SharePoint Administration

One of the biggest challenge you face while new implementation is how to Create manually so many Department Sites in Different site Collection.Also you need to create thousands of Sub Sites and Document Libraries,Calanders announcements etc. I thought of a way to over come this problem.I have written a utility which reads entire organization hierarchy from excel and and creates sames in Sharepoint.
Steps used to write this utility
1. Created Excel with desired format
excelformat
Step two :Read Excel where you have create first tab for meta data information and further tabs for each department.Each tab has list of subsites there parent Sites and details about document libararies,Calander pages which needs to be there in it.
departmentstab
Department Details show exact path where each Sub Sites and Document Library should go and shoud it show in Navigation or not
departmentsdetails
Now we are ready with all organization information.Its time to read all this data and create organization Structure in Sharepoint
First we will read Meta Data and then Department Data
readmetadata
Once you have read Meta data Created Managed Paths and then Content Database.Creating managed path is Simple while to create new content database and create department site in it you would need to make other content database offline
 string managedUrl = url + “/” + ManagedPath;

//AutomationManager.DeleteManagedPath(url, deptName, user);

Logging.LoggingManager.Instance.Info(“Creating Department Site :” + deptName);

Console.WriteLine(“Creating Department Site :” + deptName);

ExcelService.adminUserToken = AutomationManager.GetUserToken(url, user);

AutomationManager.CreateManagedPath(url, ManagedPath,user);

AutomationManager.DisableAllContentDatabaseInWeb();

SPDatabase database = AutomationManager.CreateContentDatabase(sqlServer, ContentDatabase, sqlUser, sqlPassword, WarningSiteCount, MaxSiteCount, 0);

//AutomationManager.EnableDepartmentContentDatabase(ContentDatabase);

if (database != null)

{

parentDeptSite = AutomationManager.CreateSite(managedUrl, title, desc, 1033, “SPSPORTAL#0”, domain + @”\” + user, “”, “”, “”, “”, “”, Quota, warning,portalName,portalUrl);// domainuser, deptName, deptName, “This site is created automatically”);

for (int p = 2; p <= worksheets.Count; p++)

{

Worksheet deptWorksheet = (Worksheet)worksheets.get_Item(p);

if (deptWorksheet.Name == title)

{

ProcessDepartments(managedUrl, title, deptWorksheet);

break;

}

}

parentDeptSite = null;

}

Above Code first creates Managed Path then brings all content database offline .Checks If for department content database exists if not it create it and makes it online so that new Site Collection can be added to it.
Code to create Site Collection
 mySiteCollection = ExcelService.webApplication.Sites.Add(siteUrl, title, description, nLCID, webTemplate, ownerLogin, ownerName, ownerEmail);

mySiteCollection.Quota.StorageMaximumLevel = StorageMaximumLevel; //1GB

mySiteCollection.Quota.StorageWarningLevel = StorageWarningLevel; //90% S ite

mySiteCollection.PortalName = portalName;

mySiteCollection.PortalUrl = portalUrl;

Once new Site Collection you would want that Department Site Collaction has to be Collaboration Portal but it should not have show subsites which comes with it like News,Document Center  Report Center etc.
 public static void DeleteAllSubWebs(string siteUrl, string siteName, SPUserToken adminUserToken)

{

try

{

string METHODNAME = MethodInfo.GetCurrentMethod().DeclaringType.FullName + ” . DeleteAllSubWebs(string siteUrl, string siteName, SPUserToken ExcelService.adminUserToken) – “;

Logging.LoggingManager.Instance.Debug(METHODNAME + “METHOD ENTRY: “);

Logging.LoggingManager.Instance.Info(METHODNAME + “METHOD PARAMETERS :” + siteUrl + “,” + siteName + “,” + “ExcelService.adminUserToken” );

using (SPSite site = new SPSite(siteUrl, ExcelService.adminUserToken))

{

SPWebCollection coll = site.AllWebs;

foreach (SPWeb web in coll)

{

Logging.LoggingManager.Instance.Info(“Calling DeleteWeb for :” + web.Title);

DeleteWeb(web);

}

}

}

catch (Exception exp)

{

Logging.LoggingManager.Instance.Error(exp);

Console.WriteLine(exp.GetType().Name);

}

}

Now you departments Site is ready to create sub Sites and Document Libraries. Next we will read all Departments Tab Check what type of SubSite and Libararies are required and then we will create it
Here is some code to help you do that
 if (rootWeb != null)

{

switch (objectType.ToLower())

{

case “document library”:

{

using (rootWeb)

{

Console.WriteLine(“Adding Document Library “+ child);

Logging.LoggingManager.Instance.Info(“Adding Document Library “ + child);

SPListCollection lists = rootWeb.Lists;

SPListTemplateType listTemplateType = new SPListTemplateType();

listTemplateType = SPListTemplateType.DocumentLibrary;

lists.Add(child,desc, listTemplateType);

Console.WriteLine(“Document Library “ + child + “Added Successfully”);

Logging.LoggingManager.Instance.Info(“Document Library “ + child + “Added Successfully”); ;

}

break;

}

case “calendar”:

{

using (rootWeb)

{

Console.WriteLine(“Adding Document Library “ + child);

Logging.LoggingManager.Instance.Info(“Adding Calander Library “ + child);

SPListCollection lists = rootWeb.Lists;

SPListTemplateType listTemplateType = new SPListTemplateType();

listTemplateType = SPListTemplateType.Events;

lists.Add(child, desc, listTemplateType);

Console.WriteLine(“Calander Library “ + child + “Added Successfully”);

Logging.LoggingManager.Instance.Info(“Calander Library “ + child + “Added Successfully”); ;

}

break;

}

So now you are Close to Complition and you want your navigation has to be consistent in all site Collections.You want to show Department name across all site collections.No Probelem we can add navigation.

Below Code tells how to handle navigation

PublishingWeb myPublishingWeb = PublishingWeb.GetPublishingWeb(site.RootWeb);

myPublishingWeb.IncludePagesInNavigation = false;

myPublishingWeb.IncludeSubSitesInNavigation = false;

//myPublishingWeb.NavigationOrderingMethod = OrderingMethod.Automatic;

//myPublishingWeb.NavigationAutomaticSortingMethod = AutomaticSortingMethod.Title;

//myPublishingWeb.NavigationSortAscending = true;

myPublishingWeb.Update();

 

SPNavigationNodeCollection quickLaunchNodes = web.Navigation.QuickLaunch;

SPNavigationNodeCollection topNavigationNodes = web.Navigation.TopNavigationBar;

 PublishingWebCollection publishingWebs = PublishingWeb.GetPublishingWeb(web).GetPublishingWebs();

 

So here you are done with Creating entire organization structure from Excel.

I am currently working on a Tool which will handle end to end Migration from Sharepoint2003 to 2007 ,2007 to 2007 and file System to MOSS2007. I know there are lot of products available in Market.but this Tool will help users to Move Data with Custom Meta Data which you can add on Fly.Soon will write a blog on it and Once tool is devloped i will post it on codeplex.

If you need more information write to me at akhilesh.gandhi@gmail.com

Advertisements