Renaming or Reparenting a Site in MOSS 2007


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.

STSADM

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.

Examples:

stsadm -o renameweb -url http://server/sampleweb -newname example (this will rename the web to a URL of http://server/example)

stsadm -o renameweb -url http://server/sites/foo/test/bar -newname bar (this will rename the web to a URL of http://server/sites/foo/bar)

stsadm -o renameweb -url http://server/sites/foo/bar -newname test/bar (this will rename the web to a URL of http://server/sites/foo/test/bar)

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.

  1. Expand the tree on the right hand side to find the site you want to move
  2. Click on the parent of that site in the right hand tree to load the left hand panel
  3. Check the checkbox next to the site you want to move
  4. Click on the Actions -> Move menu option
  5. Expand the tree in the popup Move dialog to find the new parent site
  6. 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.

SharePoint API

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;

     web.Update();

}

This would rename http://server/site/subsite to http://server/site2.  Changing newRelativeUrl to:

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.




    Did we save you time and headaches? Buy us some
    cups of coffee. The more coffee we drink the more
    articles we can write.

Leave a Comment Here's Your Chance to Be Heard!