Skip to main content

Click Mice, Unclick Mice

Go Search
Home
Wikin
Windows Live ID Authentication
  

Click Mice, Unclick Mice > Posts > Reparenting a Site in SharePoint

 Posts

Reparenting a Site in SharePoint
WSS v3 and MOSS 2007 have given us new capabilities from an administrative point of view with at least 3 different ways to reparent 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. 

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.

Comments

site under quick link

The code works great.  The issue i am having that now the parnet site does not show the new site.  Any ideas how to add it via code or resync it.
Keith Bunge at 4/22/2008 11:50 PM

Re: site under quick link

Not sure I understand exactly what you seeing.  Are you referring to the site not appearing at all, or just in the Quick Launch left navigation?  Also is this WSS or MOSS?
Keith Bunge at 4/22/2008 11:50 PM

getting error

I am getting an exception saying "trying to move the root web"
umesh.gavade@hotmail.com
ram.chenna@hotmail.com
Keith Bunge at 4/22/2008 11:50 PM

Excelent

Thanks, everything went fine, I used the UI but it renamed the URL, it was a 1 step process. =)
Keith Bunge at 4/22/2008 11:50 PM

how to rename the top-level site

from

http://server/sites/foo

to

http://server/sites/bar

Anyeasy way that's not required to back up and restore site?

Thanks in advance.
Khun T
Keith Bunge at 4/22/2008 11:50 PM

Thanks!

This is what i'm searching for!
Code works
LeonB
Keith Bunge at 4/22/2008 11:50 PM

how to rename the top-level site

ya ya, i also looking for this!!!

but i think the only way, r
Keith Bunge at 4/22/2008 11:50 PM