First, you'll need a reference area structure as input. This will function as a template to the areas and subareas you need to create from the utility. Put the reference area structure in an XML file and use it as a reference while creating all the subareas under each customer. The goal is to build a quick-usage utility that any user can run. The external XML files need to be bundled along with the utility. The person running it should also remember to edit the XML in case the folder structure needs to be modified.
Another way to do this is to create a hidden area in SPS itself which will replicate the exact folder structure you need. You can use it as a reference area, read it using the SharePoint API, and as a guide to create subareas under each customer area. Next, you will need a list of customers based on which areas will be created. This utility application uses hard coded values for the customer list, but you can modify the code to read the customer list from a database, flat file, or even an existing Sales/Lead Management application.
The SharePoint namespaces to include are:
In order to do anything with the SharePoint Portal, the code first needs to connect to the SharePoint Portal Server instance:
PortalContext portalContext = null;
TopologyManager topologyManager = new TopologyManager();
Uri uri = new Uri(strURL);
PortalSiteCollection sites = topologyManager.PortalSites;
portalContext = PortalApplication.GetContext(sites[uri]);
The above code establishes a connection to the running instance of the SharePoint Portal Server and gets a reference to the site pointed by the strURL variable. Once you've got the context of the site you want your areas in, go to the topics area, and the Customers area under it.
Guid topicsGuid = AreaManager.GetSystemAreaGuid( portalContext, SystemArea.Topics );
Area topicsArea = AreaManager.GetArea( portalContext, topicsGuid);
Area rootArea = null;
foreach(Area subArea in topicsArea.Areas)
if(subArea.Title == "Customers")
rootArea = subArea;
The above code uses the Customers area, which is under the main Topics area, as the base root area. Manually create a hidden area in it called Customer Template Area, and create the structure tree underneath as depicted in Figure 1
Next, find the hidden area that you'll be using as a template and replicate its structure:
foreach(Area subArea in rootArea.Areas)
if(subArea.Title == "Customer Template Area")
The above code enumerates all the subareas under the Customer area, which is the root Area, finds the area called the "Customer Template Area" and returns a handle. Use this to read the area tree structure, and replicate the area tree structure under each customer's area.
Now that you're ready to replicate the root area and the template area for all customers, you need a list of customers. This list can be read from a database, XML file, text file, or any other data source. For this example, just populate an Arraylist manually and use it as the list of customers:
Now, create an area for each customer in your list and recursively create all the subareas under the customer areas:
private void CreateArea(Area SourceArea, Area TargetArea, string title)
Area newArea = TargetArea.Areas.AddArea(title,TargetArea.Web.Name,SourceArea.AreaTemplate.ToString
foreach(Area subArea in SourceArea.Areas)
You've just successfully replicated the template area structure for each and every customer in your customer list. The full code is displayed in Listing 1
This utility can be further extended in numerous ways. For starters, you can hook the code up with some document library handling to automatically replicate your current Windows folder structure, as well as upload the documents in the Windows folders to your SharePoint document library are area listings for each subarea.
You can use it to recursively enumerate through the entire area structure and create hierarchical navigation for your portal. Or use it to compare the existing areas to a template structure and update/delete the subareas, thus synchronizing them to the template structure. You can also use it to delete all the area structures or selectively delete particular areas.
There are endless possibilities on how you can modify this code provided in Listing 1, to suit your needs and get your work done exactly the way you want it.