WSS v3 and MOSS 2007 have given us new capabilities from an administrative point of view with at least 3 different ways to reparent/rename a site within a site collection without having to resort to messy SQL changes or many backups and restores.
It is important to point out here that you can only use these methods to rename webs inside the same site collection and that the new name’s full path must exist.┬á I.e. don’t rename a web to test/bar if there is no web named test.┬á
Please note: You cannot rename a root level site collection. Your only choice is a content migration if you want a rename.
This is by far the easiest method to use and has all the functionality available.┬áThough I may be a little partial since I love a good command line application.┬á You will find STSADM in your SharePoint bin directory usually located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin and it has a handy renameweb operation built in to it.
Should also mention if it isn’t obvious from the examples that the newname variable is site collection relative.
SiteManager web UI
First you will need to bring up the UI.┬á The URL to the Site Manager is only available in MOSS and you can find it at http://server/_layouts/SiteManager.aspx.┬á Now you can change that to any site url and add the _layouts/SiteManager.aspx, but keep in mind that if you are moving things around you probably want to hit the top-level of the site collection to do this.┬á
Once you have the Site Manager page up it is pretty simple to use.
- Expand the tree on the right hand side to find the site you want to move
- Click on the parent of that site in the right hand tree to load the left hand panel
- Check the checkbox next to the site you want to move
- Click on the Actions -> Move menu option
- Expand the tree in the popup Move dialog to find the new parent site
- Click on the parent site in the tree and click the Ok button
This method has the benefit of being more visual, however it does lack so of the power of STSADM since you can’t rename the URL with it.┬á You have to go in to Site Actions -> Site Settings -> Title, description, and icon to change the URL name.┬á This mean a two step process to reparent and rename a web through the Web UI as opposed to the one step with STSADM.
The last method for reparenting a site is using the SharePoint API.┬á Microsoft has made it much easier to manage this now and actually went so far as to make the ServerRelativeUrl property read/write.┬á So the easiest way to explain how to use the API is probably to give a sample.
string fullUrl = “http://server/site/subsite“;
string newRelativeUrl = “/site2”;
using (SPSite site = new SPSite(fullUrl))
using (SPWeb web = site.OpenWeb())
┬á┬á┬á┬á web.ServerRelativeUrl = newRelativeUrl;
string newRelativeUrl = “site2”;
Would rename the┬áhttp://server/site/subsite to http://server/site/site2.┬á Just to give you an idea of the difference between┬áhow to rename the┬áUrl in the┬áparent web┬ávs. renaming the Url in the┬ásite collection.