Question from a forum post at http://www.sharepointu.com/forums/p/4055/10709.aspx:
When creating a site template, is there a way to name a set of lists and/or document libraries based on the name of the site that is chosen when creating a new site based on a custom site template? For example, creating a new site called “Peter Pan” and then having the list and doc library (in the template) named “Peter Pan List” and “Peter Pan Doc Library” automatically after creation of the site.
You can do this relativly easy in a featureactivated event handler, but it does require a bit of coding and provisioning the lists or sites as features or site definitions. If programming is ok with you and you are able to work with the SharePoint OM, you would go about this in one of two ways.
First you can provision the site as a site definition and have a webfeature or sitefeature that has an event handler to rename the lists. Doing this the feature way can in turn be done in one of two ways. First, you can have a ‘rename lists’ feature that renames lists when the feature is activated through the site definition. One downside to this is that any future lists added will not be renamed. One upside, amongst others, is that you can rename lists regardless of the lists themselves, that is, any list, regardless of how that list is provisioned through the site definition, can be renamed. The other way to do this features based is to add all lists as features and have the event handlers attached to those features. The downside is that you wont be using the ‘Create’ option of the site actions or view all site content page. The upside is that you can do this also after the site has been provisioned so that all new lists will be named accordingly.
The other option for renaming lists is to use a little known site provisioning object model. This technique is used by the collaboration portal in MOSS, but is available to WSS if you are willing to walk the coding lines. Again, this only works when you are provisioning sites, not for creating lists after the fact. To do this you would use the ProvisionData, ProvisionAssembly and ProvisionClass as attributes to your site definition in webtemp*.xml. If you want to go down this route, and it may be usefull anyways if only for the exercise, Anders Jacobsen has written a short article that gets you started:
The huge benefit of the latter option, using the SPWebProvisioningProvider, is the flexibility you get from having complete programmatic access to site provisioning. You can add users, create on-the-fly lists, build workflows and connect them to content types or lists based on any criteria (how about appending I HATE MONDAYS to all items on a site created on Monday mornings?) or basically anything else you can do to a site. Best, or worst, part is, you dont even need a site definition outside the webtemp*.xml, you can create your entire site inside code. In fact, this is what the collaboration portal does, you will not find a SPSPORTAL site definition anywhere, but rather a reference to an assembly that does the entire provisioning through code.
Found this article valuable? Want to show your appreciation? Here are some options:
a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.
b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.
c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!