MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Tuesday, September 4, 2007

Convert a Sub-site to a Site Collection

I finally figured it out! This was supposed to be one of those very simple tasks that I should have been able to do without any custom code. Turning a sub-site (or web) into a site collection (or top level site) turned out to be the most difficult task I've yet to face with SharePoint 2007. In theory you should be able to do this using the following commands which could be put into a batch file:

REM Create a test web for exporting
stsadm -o createweb -url "http://intranet/testweb" -sitetemplate "SPSTOPIC#0"

REM Export the test web to the filesystem
stsadm -o export -url "http://intranet/testweb" -filename "c:\testweb" -includeusersecurity -versions 4 -nofilecompression -quiet

REM Create a managed path for the new top level site
stsadm -o addpath -url "http://intranet/testsite" -type explicitinclusion

REM Create an empty site with a default site template (note that if you don't specify a template you have to manually activate the required features)
stsadm -o createsite -url "http://intranet/testsite" -owneremail "someone@example.com" -ownerlogin "domain\username" -sitetemplate "SPSTOPIC#0"

REM Import the site
stsadm -o import -url "http://intranet/testsite" -filename "c:\testweb" -includeusersecurity -nofilecompression -quiet

Unfortunately what you get is only a partially functional site (and in some case not functional at all). There are several errors that you are likely to encounter after running the above using the created testweb or your own existing web. The first and most obvious error is that when you load the default.aspx page of the new site you may get a File Not Found error (note that running the above as is will not give you this error). This is the result of the publishing pages PageLayout URL getting messed up (effectively still pointing to an old value). I addressed this specific issue with a separate command (http://stsadm.blogspot.com/2007/08/fix-publishing-pages-page-layout-url.html) and the I've encapsulated that functionality into the new commands I've created which are detailed below.

The next error you're likely to see is on the Area Template Settings page (Site Settings -> Page layouts and site templates). The specific error is "Data at the root level is invalid. Line 1, position 1".

Anyone who's done a lot of XML work should recognize this error as an XML parsing error. This error occurs if the web you imported from was set to inherit it's page layouts from it's parent. When a web is setup this way there's a property called "__PageLayouts" which gets set to "__inherit".

For a top level site collection this value should always be either an empty string (all page layouts are available) or XML describing which layouts are available. The import operation does not consider this and leaves the value as is thus resulting in the XML error when attempting to parse "__inherit" as XML. The fix for this is simple enough - change the value to an empty string. Unfortunately that's not all we have to do. Fixing the above error results in the page loading without errors, however, the page layouts section does not load. There's still several issues that need to be resolved. If you now go and view the master gallery (Site Settings -> Master pages and page layouts) you should see all the default page layouts. If you have any custom page layouts those won't exist and will cause problems.

Also, if you attempt to edit a file you'll notice that even though we used a publishing template it doesn't prompt you to check the file out. What's more is that once you view the form for a layout you should see that only the core fields are present (no Content Type, Associated Content Type, Variations, etc.).

There are several things that need to be fixed here - first we need to activate all the features that would otherwise be activated on a new site collection (need this so that we can get the publishing workflow options enabled). Second we need to reset all the properties for the gallery to match that of our source gallery (namely we need to allow management of content types).

Third we have to change the ContentType field from being a Text field to being a Choice field (more about this in a minute). Fourth we need to re-associate each file as a Page Layout file by setting all the necessary properties (Content Type, Associated Content Type, etc.). In regards to changing the ContentType field this is the one that caused me the most headache to figure out. For some reason during the import of the site this field gets a bit messed up (note that I'm not referring to the ContentType field that is linked in from the Page content type which is associated with the library but rather another field that is part of the gallery definition itself). The field should be a Choice field with options such as "Page Layout", "Publishing Mater Page", "Master Page", and "Folder". However, during the import the field is converted to a Text field - don't ask me why.

The result is that when you query for the list of available page layouts the unmanaged code that Microsoft uses to do the actual query chokes because it can't find a matching value in the list so it produces an invalid query which will always return no results back. To fix this I copy the source master page gallery on top of the target gallery using the content deployment API. I also found that (with SP2) the PublishingResources feature seemed to correct the issue (at least in the tests that I ran).

UPDATE 9/4/2007: I just discovered that another issue is related to the global navigation. If you view the navigation via the browser it will look as though everything is just peachy but if you attempt to manipulate the navigation programmatically you'll find that the PublishingWeb's GlobalNavigationNodes property is empty (no items are present). This is because the global navigation is stored at the site collection level so when you import the web it does not take the global navigation with it, just the current. The fix is simple enough - just loop through the current navigation collection and copy it to the global navigation collection. This will help to allow other programmatic manipulations of the global navigation to succeed.

UPDATE 7/6/2009:  I am now calling the code that I created to copy content types from one site collection to another.  This solves issues that can occur if a site collection content type was not created via a Feature.  I've also added additional logging to better show what is happening.

So, to summarize the things that need to be repaired after importing into your empty site collection:

  1. Activate any features that are needed by the site
  2. Set the master page gallery settings
    1. Enable content type management
    2. Set your publishing options
    3. Fix the Content Type field so that it's a Choice field type by copying the source master page gallery
  3. Copy missing content types from the source site collection.
  4. Fix the Page Layouts and Site Templates
    1. Set the "__PageLayouts" property to an empty string (can then be set to something else using SetAvailablePageLayouts() but first needs to be set to an empty string as SetAvailablePageLayouts() will not work until it's fixed)
    2. Copy any missing page layouts from the source
    3. Set all appropriate properties on each page layout
  5. Fix all the publishing pages PageLayout property to have the correct URL
  6. UPDATE 9/4/2007: Update the global navigation

Some of the above can be done via the browser but most of it requires programmatic changes. In order to solve all these problems I've created two custom stsadm commands - the first will take a site make all the repairs identified above (so it assumes you've already imported the site).

The second basically just abstracts the whole process of exporting a web, creating a site, importing into the site, and then repairing the site (this way the entire process can be done with just one command). The commands I created are detailed below (forgive the verbosity of the names - I had trouble coming up with something shorter).

1. gl-repairsitecollectionimportedfromsubsite

The code is fairly well documented so rather than discuss it all (there's a lot of it) I've linked it to this post here. The syntax of the command can be seen below:

C:\>stsadm -help gl-repairsitecollectionimportedfromsubsite

stsadm -o gl-repairsitecollectionimportedfromsubsite

Repairs a site collection that has been imported from an exported sub-site.  Note that the sourceurl can be the actual source site or any site collection that can be used as a model for the target.

Parameters:
        -sourceurl <source location of the existing sub-site or model site collection>
        -targeturl <target location for the new site collection>

The following table summarizes the command and its various parameters:

Command Name Availability Build Date
gl-repairsitecollectionimportedfromsubsite WSS 3, MOSS 2007 Released: 9/4/2007
Updated: 7/6/2009

Parameter Name Short Form Required Description Example Usage
sourceurl source Yes The URL to the source sub-site to convert. -sourceurl http://portal/subsite

-source http://portal/subsite
targeturl target Yes The URL of the new site collection to create. -targeturl http://portal/sites/site

-target http://portal/sites/site

Here’s an example of how to repair the site created using the batch file above:

stsadm –o gl-repairsitecollectionimportedfromsubsite –sourceurl "http://intranet/testweb/" -targeturl "http://intranet/testsite/"

2. gl-convertsubsitetositecollection

As stated above, this command is just an abstraction of other commands - it simply calls out to stsadm to do export the site (note that you can provide a previously exported site file/folder), create the managed path, create the empty site, import the site, and finally repair the imported site. As there's nothing spectacular going on here I didn't bother culling the code out in this post (download the project if you're interested in the details). The syntax of the command can be seen below:

C:\>stsadm -help gl-convertsubsitetositecollection

stsadm -o gl-convertsubsitetositecollection


Converts a sub-site to a top level site collection via a managed path.

Parameters:

        -sourceurl <source location of the existing sub-site or model site collection>
        -targeturl <target location for the new site collection>
        -owneremail <someone@example.com>
        [-createmanagedpath]
        [-haltonwarning]
        [-haltonfatalerror]
        [-includeusersecurity]
        [-suppressafterevents (disable the firing of "After" events when creating or modifying list items)]
        [-exportedfile <filename of exported site if previously exported>]
        [-nofilecompression]
        [-ownerlogin <DOMAIN\name>]
        [-ownername <display name>]
        [-secondaryemail <someone@example.com>]
        [-secondarylogin <DOMAIN\name>]
        [-secondaryname <display name>]
        [-lcid <language>]
        [-title <site title>]
        [-description <site description>]
        [-hostheaderwebapplicationurl <web application url>]
        [-quota <quota template>]
        [-deletesource]
        [-createsiteinnewdb]
        [-createsiteindb]
        [-databaseuser <database username>]
        [-databasepassword <database password>]
        [-databaseserver <database server name>]
        [-databasename <database name>]
        [-verbose]

The following table summarizes the command and its various parameters:

Command Name Availability Build Date
gl-convertsubsitetositecollection WSS 3, MOSS 2007 Released: 9/4/2007
Updated: 7/6/2009

Parameter Name Short Form Required Description Example Usage
sourceurl source Yes The URL to the source sub-site to convert. -sourceurl http://portal/subsite

-source http://portal/subsite
targeturl target Yes The URL of the new site collection to create. -targeturl http://portal/sites/site

-target http://portal/sites/site
owneremail oe Yes

The site owner's e-mail address.  Must be valid e-mail address, in the form someone@example.com.

-owneremail someone@example.com

-oe someone@example.com
createmanagedpath createpath No Create a new managed path for the site collection. -createmanagedpath

-createpath
haltonwarning warning No Stop execution of the command if a warning event occurs during the export or import process. -haltonwarning

-warning
haltonfatalerror error No Stop execution of the command if a fatal error occurs during the export or import process. -haltonfatalerror

-error
exportedfile file No Use a previously exported site (created using stsadm's export command). -exportedfile c:\exportdata\site

-file c:\exportdata\site
nofilecompression   No Do not compress the site when exporting (or if previously exported use an uncompressed file for the import). -nofilecompression
ownerlogin ol

If your farm does not have Active Directory account creation mode enabled, then this parameter is required.

This parameter should not be provided if your farm has Active Directory account creation mode enabled, as Microsoft Office SharePoint Server 2007 will automatically create a site collection owner account in Active Directory based on the owner e-mail address.

The site owner's user account.  Must be a valid Windows user name, and must be qualified with a domain name, for example, domain\name

-ownerlogin domain\name

-ol domain\name
ownername on No

The site owner's display name.

-ownername "Gary Lapointe"

-on "Gary Lapointe"
secondaryemail se No

The secondary site owner's e-mail address.  Must be valid e-mail address, in the form someone@example.com.

-secondaryemail someone@example.com

-se someone@example.com
secondarylogin sl

If your farm does not have Active Directory account creation mode enabled, then this parameter is required.

This parameter should not be provided if your farm has Active Directory account creation mode enabled, as Microsoft Office SharePoint Server 2007 will automatically create a site collection owner account in Active Directory based on the owner e-mail address.

The secondary site owner's user account.  Must be a valid Windows user name, and must be qualified with a domain name, for example, domain\name

-secondarylogin domain\name

-sl domain\login
secondaryname sn No

The secondary site owner's display name.

-secondaryname "Pam Lapointe"

-sn "Pam Lapointe"
lcid   No

A valid locale ID, such as "1033" for English.  You must specify this parameter when using a non-English template.

-lcid 1033
title t No

The title of the new site collection (this value will be overwritten when the site is imported - it is available only to help in situations in which the import fails).

-title "New Site"
description desc No

Description of the site collection (this value will be overwritten when the site is imported - it is available only to help in situations in which the import fails).

-description "New Site Description"

-desc "New Site Description"
hostheaderwebapplicationurl hhurl No

A valid URL assigned to the Web application by using Alternate Access Mapping (AAM), such as "http://server_name".

When the hostheaderwebapplicationurl parameter is present, the value of the url parameter is the URL of the host-named site collection and value of the hostheaderwebapplicationurl parameter is the URL of the Web application that will hold the host-named site collection.

-hostheaderwebapplicationurl http://newsite

-hhurl http://newsite
quota   No

The quota template to apply to sites created on the virtual server.

-quota Portal
deletesource   No Delete the source site after conversion (only recommended if significant testing has occurred). -deletesource
createsiteinnewdb newdb No Create the site collection in a content database. -createsiteinnewdb

-newdb
createsiteindb db No Create the site collection in an existing content database. -createsiteindb

-db
databaseserver ds No The database server containing the specified content database.  If not specified then the default database server is used. -databaseserver spsql1

-ds spsql1
databaseuser du No

The administrator user name for the SQL Server database.

-databaseuser domain\user

-du domain\user
databasepassword dp No

The password that corresponds to the administrator user name for the SQL Server database.

-databasepassword password

-dp password
databasename dn Yes if createsiteinnewdb or createsiteindb is specified.

The name of the content database to put the site collection in (will be created if createsiteinnewdb is specified).

-databasename SharePoint_Content1

-db SharePoint_Content1
suppressafterevents sae No Disable the firing of After events when creating or modifying files or list items during the import. -suppressafterevents

-sae
verbose v No Displays logging information when executing. -verbose

-v

Here's an example of how to do all that the batch file above is doing (minus the creation of the testweb) as well as the repair operation all with one command:

stsadm –o gl-convertsubsitetositecollection –sourceurl "http://intranet/testweb/" -targeturl "http://intranet/testsite/" -createmanagedpath -nofilecompression -owneremail "someone@example.com" -ownerlogin "domain\user" -deletesource

One area of improvement may be to pull the owner and secondary owner information from the source site collection so that this information does not have to be provided - maybe I'll do that if I feel I have the time or if people express enough interest. Note that you can specify a title and description but they'll be overwritten during the import - I only included them so that if the import fails and you're left with an incomplete site you'll at least have a name for it if you should forget to delete it and stumble upon it a year later.

Figuring out how to solve all the issues surrounding converting a web to a site collection was a real pain the a$$ so any feedback that people have on this would be greatly appreciated - hopefully if there are others out there that have stumbled on this then they'll benefit from it as well. Keep in mind also that though I think I've solved all the errors related to the conversion it's possible that different implementations may have additional errors that I have not seen - if that's the case please let me know (especially if you've solved the problems) so that I can share with others.

Update 9/21/2007: I've fixed a couple minor bugs that pop up when converting a non-publishing site. I've also enhanced the command to take advantage of another new command I created: gl-updatev2tov3upgradeareaurlmappings (updates the url mapping of V2 bucket webs to V3 webs thereby reflecting the change of url as a result of the move so if a user tries to hit the V2 url it will redirect to the new and updated V3 url).

Update 10/2/2007: I've enhanced the command to take advantage of another new command I created: gl-retargetcontentquerywebpart (fixes Grouped Listings web parts that remained pointed at the old list rather than the newly imported list).

Update 10/12/2007: I've removed the retainobjectidentity parameter. If you attempt to use this parameter you will receive a syntax error. Turns out that retaining the object identity when going from a sub-site to a site collection just created a nightmare. However, because I still had to handle these web parts that were broken I decided to enhance the repair routines to manually retarget the DataFormWebPart and ContentByQueryWebPart web parts. So if a matching list can be found on the source then any of these web parts on your pages should be fixed so that you don't have to manually fix them (the gl-repairsitecollectionimportedfromsubsite command will do the same).

Update 7/6/2009: I removed the direct DB access code and added support for copying content types from the source.

205 comments:

1 – 200 of 205   Newer›   Newest»
Gary Lapointe said...

One thing I forgot to mention - if you are testing the import of a web into a site collection repeatedly make sure that you delete the site collection via the Site Settings->Delete Site command and not from the central admins delete site collection command - for some odd reason the central admin tool does not clean everything up and when you do your import you'll get even stranger behavior than the normal strange behavior (this one took me a while to figure out - I was chasing several errors that only manifest when you delete via central admin - deleting from the site itself did not result in the errors). One specific issue you'll see is that when you view the list of content types nothing will show up - strange stuff...

Søren said...

This is brilliant.

I'm believe I'll be facing the same challenge in the near future, this will definitely come in handy.

Thanks.

Gary Lapointe said...

Thanks for the feedback - I definitly appreciate it. I do have an update - I just discovered that the global navigation is also not set correctly after the import. I've updated the content in the post and posted an updated version of my code.

rob holloway said...

I found an issue when I tried running your convertsubsitetositecollection. It seems when the export file is created the .cmp file extension is not included in the filename variable, so when you go to import the file after creating the site an error occurs:

Importing Site
The file C:\Documents and Settings\spuser\Local Settings\GUID does not exist.

Error occured importing site.

What I did was modify the code in this section:

string filename;
if (!keyValues.ContainsKey("exportedfile"))
{
Console.WriteLine("Exporting site...");
filename = ExportSite(sourceurl,keyValues.ContainsKey("haltonwarning"),keyValues.ContainsKey("haltonfatalerror"),keyValues.ContainsKey("nofilecompression"));

Added this line ->
filename += ".cmp";
Console.WriteLine("Site exported.\r\n");
} }

Gary Lapointe said...

Thanks for the info - I did most of my testing using the "nofilecompression" option as it runs a bit faster and is considered by Microsoft to be slightly more reliable (not sure why but Bill Baer recommended I use this option in preference to the compression). I added a fix that to the ExportSite static method so that it adds the extension if compression is used:

if (!noFileCompression)
filename += ".cmp";

I've uploaded that change so feel free to download. If you find any other issues please let me know - I've got so much on my plate I that I tend to forget to test some scenarios.

rob holloway said...

Gary

Another issue I am having. This one maybe my environment. When I run the command repaircollectionimported.....

I get the follwoing error:

Invalid URI: The Authority/Host could not be posted

Here is the command line:
stsadm -o repairsitecollectionimportedfromsubsite -sourceurl "http://siteA/subsiteA/" -targeturl "http://siteB/subsiteB"

Any ideas why I am getting this error?

Gary Lapointe said...

I haven't actually seen that particular error before. If you could step into the code and tell me on what line the error is occuring (and any other details such as method parameters, local variable values, etc.) then I could probably give you an idea of what's happening (I've found that the easiest way to do this is to add System.Diagnostics.Debugger.Launch() to the Run method - this should launch your debugger (hopefully you have an environment with VS2005 on it that you can test with). My email is glapointe at edfinancial dot com - feel free to email me directly (I'll need more specifics from you regarding the sites in order to try and replicate here - if it's possible to send me your exported files that would really help).

Gary Lapointe said...

Forgot one more thing you can try to narrow down the possibilities - try running the FixPublishingPagesPageLayoutUrl command separate (the repair command calls this so if you can get the error with this command then we've at least narrowed the scope - this is assuming of course that you can't get into the debugger which would be much easier :))

Gary Lapointe said...

Update 9/19/2007 - I fixed a minor issue with the deletesource parameter - it would only delete the source if there were no sub-webs; now it will delete the source recursively so having sub-webs no longer matters.

Gary Lapointe said...

Update 9/19/2007 - I just added another new switch "-donotcreatesite" which basically just causes the code to skip the createsite call. This is handy if you are migrating a sub-site to a root site collection and you've already used the extendvs command to create the web app. Note that I just discovered that going from a sub-site to a root site collection on a different web app seems to be throwing some sort of odd exception in the repair call - I'm currently working on reproducing the problem in my test environment and should hopefully have a fix soon.

Gary Lapointe said...

I figured out the problem I was having. It was pretty stupid really - I was getting an ArgumentException when checking for the existence of an item in a collection (I was looking for the return to be null). I guess I forgot that some collections (not all of them mind you) throw an exception if no match was found rather than just returning null - very annoying. Anyways, the code has been fixed and is now available. The bug was in the FixPageLayoutsAndSiteTemplates method within the main foreach loop - I just changed it to set a variable wrapped in a try/catch and that fixed it (not sure why it didn't fail on me before because I've stepped into this code numerous times before - strange).

bind00 said...

Can anyone suggest how to do the reverse, ie. convert a site collection into a subsite? My subsites seem to have become individual site collections during the upgrade to WSS3.0. I used to be able to open lists on other subsites using the Data Source Catalog/Library but that doesn't work any more.

Gary Lapointe said...

I haven't tried it but I've heard that you can use the backup and restore commands to do it. I'll probably have to play around with this very thing in the near future (if you figure it out please post back).

Collin Ames said...

I believe I got the custom STSADM commands installed in the GAC correctly. When I tried to run the convertsubsitetositecollection command, I got the following error:

Value cannot be null.
Parameter name: type


I don't actually see a "type" parameter in the code, so any ideas what is going on here?

Thanks!

Gary Lapointe said...

This error occurs when the DLL is not GAC'd properly. Make sure the DLL is GAC'd and you should be all set.

Philby001 said...

Thanks for the information - can be very handy from trying to migrate a sub-site as a site collection - however, what about the other way around - is there a way of migrating a site collection to become a sub-site of an existing site collection?

Gary Lapointe said...

In order to test going from a site collection to a sub-site I did a quick test which worked for me. Basically I just used the built-in export command to export the site collection and then used the built-in import command to import to a new web (after using createweb to create a shell web site). My test was pretty simple as I didn't have any custom content types or page layouts so I'm not sure how well this works in those situations. I noticed that it did create a master pages gallery as part of the web site and it "appears" as though the pages are using that gallery rather than the site collection gallery but I haven't looked closely enough to verify. This could be exactly what you want or it could be problematic - it really just depends on your needs. Here are the commands I used for my test which seemed to work fine:

stsadm -o export -url "http://portal/sitecollection" -filename "c:\sitecollection" -includeusersecurity -versions 4

stsadm -o createweb -url "http://portal2/newsubwebname"

stsadm -o import -url "http://portal2/newsubwebname" -filename "c:\sitecollection.cmp" -includeusersecurity -updateversions 2

I've updated my moveweb command to support this scenario.

I've also heard that you can use backup and restore but that can't be correct - I've looked into it and the restore command only allows you to restore back to a site collection so going to a sub-site does not work.

Note that I have found one potentially significant issue with exporting your site collection - if you are using the Fantastic 40 application templates you will get an error when you do the export. The error occurs when the "Fields and Content Types for the Windows SharePoint Services Application Templates" feature is active for the site collection. This feature results in several fields being added and some of those fields are lookup fields which have their SPField.LookupList value set to a name instead of a GUID. The result is that the export fails because it can't convert the name to a GUID (the specific error is: "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)" and occurs in Microsoft.SharePoint.Deployment.FieldTemplateSerializer.ParseLookups()). It's simple enough to write some code that remaps the property to point to the list ID but the problem is that the feature will add fields that point to lists that do not yet exist so you'd have to create the lists or delete the content types / fields that are not associated with a list before the export can work. As always, if anyone has some input on this please share with the rest of us.

Paul said...

Magnificent stuff. Got nailed by this and solved it via your MSDN forum post. Was going to blog it myself but then saw this.

Impressive work.. really impressive

Paul said...

I'm now your number 1 fan :-)

http://www.cleverworkarounds.com/2007/11/14/gary-lapointe-is-a-genius-and-has-good-music-taste-too/

Gary Lapointe said...

LOL - I love the title :)

Byungchul J said...

Tom Jung:
Thanks for your great tool, it really solve my headaches. Here is what I want to do, I'd like to have your advice.

Goal: I have 24 subsites under a subsite (http://intranet/president) as below, and want to convert the 24 to site collections without changing the URL. and the 24 subsites have multiple subsites underneath.

Solution: And since 'president' subsite is empty, I'll create a managed path with "president", and convert the 24 subsites to Site Collections. As you may already know my concern on "sourceurl" parameter in "repairsitecollectionimportedfromsubsite" tool, after making managed path, the source url will not available. Please let me know if you have any advice.

http://intranet/president/HR
http://intranet/president/QA
http://intranet/president/IT
http://intranet/president/...

Gary Lapointe said...

The source url would be the url of the source site collection or a site collection "model". This means that you can point to any site collection that has the settings the way you need/want them (page layouts and what not are present). So if "president" is your source site collection then you would use "http://intranet/president" as the source site url.

Dave Kelly said...

Gary, this tool is fantastic! I have one site where I'm getting an error though...I think it's not checking for null in the WebPart repair. Here's a trace dump:

Site imported.

Repairing imported site...

Error Type: System.ArgumentNullException
Error Message: Value cannot be null.
Parameter name: input
Error Source: System
Error TargetSite:System.String Replace(System.String, System.String)
Error Stack Trace:
at System.Text.RegularExpressions.Regex.Replace(String input, String replacement)
at Edfinancial.SharePoint.STSADM.Commands.WebParts.ReplaceWebPartContent.ReplaceValues(SPWeb web, SPFile file, Settings settings, DataFormWebPart wp, Regex regex, SPLimitedWebPartManager& manager, Boolean& wasCheckedOut, Boolean& modified)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RetargetMiscWebParts(SPWeb targetWeb, StringDictionary listMap, SPFile file)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RetargetMiscWebParts(SPWeb targetWeb, StringDictionary listMap)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RetargetMiscWebParts(SPWeb targetWeb, StringDictionary listMap)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RetargetMiscWebParts(SPSite sourceSite, SPWeb sourceWeb, SPWeb targetWeb)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairSite(String sourceurl, String targeturl)
at Edfinancial.SharePoint.STSADM.Commands.SiteCollectionSettings.ConvertSubSiteToSiteCollection.Run(String command, StringDictionary keyValues, String& output)
Value cannot be null.
Parameter name: input


Any ideas?

Gary Lapointe said...

Dave - Thanks for the feedback. I believe I've identified the problem. I just pushed a new build out which should resolve the error.

Techaholic said...

I'm working with Customs Border Patrol and due to the size of their site collection I need to break it down into several Site Collections, so your tool is perfect for this task, however when I try to do this many of the sites and the root site come up with file not found, but if I go to site settings URL it comes up fine, just seems to be the default.aspx pages will not load for some of the sites. Any idea where it is failing and how to fix it. Thx Peter

Gary Lapointe said...

Usually this happens when the page layout is not linked up correctly. Try running the repairsitecollectionimportedfromsubsite command and see if it fixes anything (this command should have been run automatically when you ran convertsubsitetositecollection but it can't hurt it to try again. If that doesn't help then I'll need to know more information to help you further - specifically what the site structure looks like and what site templates and page layouts are in use. You can email this to me if you need to: gary at thelapointes dot com.

Techaholic said...

Gary I think I fixed it, I managed to get the site settings page to resolve, and I set the Look and Feel/ Master Page to Default and forced it to reset all subsite to the same, and up she came.

I have a little trick I learned in V2 of SharePoint that seems to still work in V3 that I will pass along. If you have an existing sub site say http"/mainsite/subsite and you create an Explicit managed path mainsite/subsite it will turn off the sub site as if it had been deleted. You can now import the subsite with your utility and create a site collection using that exact same URL space. Now here's the good part, if you delete the managed path the subsite in all its glory will reappear, and if you add the explicit managed path back the site collection will take control and magically reappear. So you can toggle between the original subsite and the newly created site collection. I found this very valuable when I was migrating sub sites to site collections without changing the URL. It allowed me instant roll back (restore original sub site just by deleting the managed path) to the original subsite if something went wrong with the upgrade, plus uses barley noticed anything had changed. When everything is fully tested for the new site collection, simply delete the managed path which will bring back the old subsite, using site settings delete the subsite and then readd the managed path to bring back the new site collection to complete the upgrade.

GeorgeS said...

Gary, I really have a tough time installing those. Do I need the Sharepoint SDK? Thanks!

Gary Lapointe said...

GeorgeS - in the download there's a Package folder - simply install the dll into the GAC and then copy the xml file over to the 12 hives config folder (the info.txt file in the download also explains this). That's it - once you've done that then you can use the commands like any other stsadm command.

GeorgeS said...

Hi Gary, when I try to import an exported site with import2, I get an error saying: Could not find WebTemplate IT#75804 with LCID 1033. Have you had a problem like this before? Thanks!

Gary Lapointe said...

Yeah - I'm familiar with that one - problem is that there's no way to determine the exact template that was used to create the source - My code gets the template name and ID from the source but the ID is not always accurate (haven't had time to figure what the deal is with that - I feel like I'm overlooking something simple though). If you encounter this then simply specify the site template to use as an argument (in your case it's probably "IT#0").

ChrisR said...

Very cool utility. I'm trying to use the convertsubsitetocollection switch and when it tries to export the site, I get an exception saying that the "User cannot be found". Do you know what this means?

Gary Lapointe said...

I believe this issue was fixed with SP1. This post provides one way around it: http://geekswithblogs.net/RogueCoder/archive/2007/05/14/112478.aspx.

ChrisR said...

Thanks for the info. That link will do it. The server isn't actually running MOSS 2007 yet so I can't install SP1. I believe there is an unreleased hotfix for WSS 3.0 but the SQL methond will do just fine. Thanks again for your help

Anonymous said...

Gary,

You are freaking awesome. We had been working on a site restore issue for hours now. We were having the exact same issue with the page layouts page throwing error and then we ran into your article. It fixed out issue in two minutes.

You are God!!!!

treiter said...

Gary,

I need help on installation of these controls on my SharePoint server. I read the info.txt and followed the instructions however when I run a stsadm command like convertsubsitetositecolletion I receive a command line error. What other steps are necessary to install the controls?

Thanks.

Tim

Gary Lapointe said...

Tim - you'll want to make sure that the dll is in the GAC and that the xml file is in the config folder. As long as both things are set then the commands should work.

treiter said...

Gary,

Tim again. Its like STSADM can't locate your command files. Do you have to copy your command files to the bin directory as well?

I did verify that the XML file is in the correct folder and the DLL is in the GAC.

Tim

Gary Lapointe said...

Tim - if the dll is in the GAC and the commands are showing up when you do "stsadm -help" (which I saw from your other comment that they are) then I'm honestly not sure why you are not seeing anything even when you do the help command. You can try to put the dll in the 12/config/bin folder and register in the GAC from there but it shouldn't make a difference (if it wasn't in the GAC then you'd get some sort of Type error when you tried to use the command or get help on the command). You may want to try and re-download (maybe something just go corrupted along the way - it's a stretch but I'm not sure what else to tell you).

treiter said...

Gary,

Ok...I redeployed the DLL and I am now able to get the commands to work. Hooray!

I just attempted to perform a convertsubsitetosite collection and it performed the export but failed on the import with access denied. I have added the parameter of ownerlogin of my machine account. Do you have to specify the password? If yes on password then what is the password parameter?

It appears that I am close now. Thanks for the support. I hope this works.

Tim

Gary Lapointe said...

The owner login just sets who the owner of the site is - you can't set a password for it. Sounds like you just don't have enough rights (or maybe self service site creation is disabled?). You'll want to run these commands using your admin account (usually the one you used to setup MOSS initially).

treiter said...

Gary,

Can not run the command "repairsitecollectionimportedfromsubsite". The command will not run...your command work fine but this one does not.

Tim

treiter said...

Gary,

Still getting file not found after running the repair command. What file or site template do you edit to set the template setting to NULL?

With a file not found in sharepoint...is there a back door method to get to sitesettings or all site content even though the site will not render?

Need help desparately.

Tim

Gary Lapointe said...

Tim - Are you getting any kind of error running the repair command? Also - you can email me at glapointe at statera dot com (little easier than going through the blog).

Gary Lapointe said...

Tim - for the file not found error unfortunately there's no way that I've found to fix this using the browser - you might try SharePoint Designer but I suspect that will fail as well. The file not found errors are usually because it can't find the page layout or the master page. I've found that some issues with the page layout are because the library doesn't have the right content types associated with it. The repair command should fix those issues (I've found a couple of occasions where I had to run it more than once though it may have just been a caching issue).

Dave@Crackerbox said...

Gary, thanks for the custom extensions...an absolute time saver. I have just converted a subsite to a site collection using your extension as I needed to move the subsite to a new server and the backup command only works on site collections.

Everything seemed to work fine with the exception of the Quick Link navigation. I have tried to go into Site Navigation Settings to correct the problems but am not able to change anything. All changes are ignored. However all was not lost as your enumnavigation identified the nav structure and settings and setnavigationnodes allowed me to import the correct urls via xml.

Michal said...

Hi Gary,

Just a quick qst, I'm redoing a customer intranet portal and have used the publishing site template as the home page and only recently noticed that I get the same error when I go to the page settings link on the toolbar. I haven't migrated anything, it's a from scratch thing. Does your code still apply and if so where does a non-developper put it with the least amount of mess?

Thanks,

Gary Lapointe said...

Michael - I haven't seen this error occur on a straight up publishing site that hasn't been moved or otherwise tampered with. Most likely the page layout url is pointing to the wrong place - you can try using the fix command from this post (just download the code - add the dll to the GAC and copy the xml file to the 12 hive's config folder). There's also some other code that may help you: http://blog.thekid.me.uk/archive/2007/08/20/fixing-page-layout-urls-after-importing-a-publishing-site-in-sharepoint.aspx.

freddy81 said...

Thanks for command, it save my life but i had to make some changes !

We are french with a french installation, so "Content Type" field is named "Type de contenu" and CAML Choices has to be in french ...

Thanks for this great job, Gary !

Paula said...

Originally posted yesterday on the import2 thread, but moved here as I decided on this command.

I created a test web app (temporary.url.com) with a portal site on top, then ran the command below (includes results). The command then locked up after the last warning message and did nothing for 30 minutes. I finally canceled it. Site is created and appears to have the same content as the original. I'm just not certain what the errors mean nor where that leaves things.

stsadm -o gl-convertsubsitetositecollection -sourceurl "http://current.url.com/subsite" -targeturl "http://temporary.url.com/site" -createmanagedpath -nofilecompression -owneremail "someone@somewhere.com" -ownerlogin "domain\spadmin" -nositetemplate -title SiteTitle
Adding managed path...
Managed path added.
Exporting site...
Site exported.
Creating site for import...
Site created.
Applying site template based on source...
Site template applied.
Setting required features...
WARNING: Unable to activate feature 'PublishingSite (FeatureDefinition/f6924d36-2fa8-4f0b-b16d-06b7250180fa)'
Provisioning did not succeed. Details: Failed to create the 'Reusable Content' library. OriginalException: Folders are not allowed for this list template.
WARNING: Unable to activate feature 'PublishingResources (FeatureDefinition/aebc918d-b20f-4a11-a1db-9ed84d79c87e)'
Provisioning did not succeed. Details: Failed to create the 'Reusable Content' library. OriginalException: Folders are not allowed for this list template.

Gary Lapointe said...

Well that's a new one - what site template is your source sub-site using? Are you able to activate teh PublishingSite feature manually using the browser or stsadm?

Gary Lapointe said...

Oh - one more thing - this may not necessarily be a bad thing - the code is trying to do it's best to get all the features that the site "may" require based on what was configured for the parent site collection of the source sub-site - so if your sub-site doesn't support publishing features but your parent sub-site's site collection does then you would get an error like this because the code is doing it's best to make sure that all features that may be getting utilized by the sub-site are reactivated at the new site collection.

Paula said...

This whole thing was upgraded from WSS to 2003 when it came out and now to 2007. I believe the whole thing is the original team site template. I've nuked the test site, so I will have to redo to see if I can manually add them.

I have had issues with trying to save lists as templates and using them where I had to go into the xml and change the version from 2 to 3 for it to work. Could be the same thing here.

graydo64 said...

Can I start by echoing everyone else's sentiment? Thank you for these extensions, they've saved me hours of work.

I just wanted to point out a slight issue I had with convertsubsitetositecollection. We have a number of sub-sites created when our farm was WSS3.0. We've now upgraded to MOSS and want to do some re-organisation by changing the larger sites to site collections. I've found that after running gl-convertsubsitetositecollection the navigation is broken on the target site. As per a previous comment on this post I tried using the operation to copy navigation but sadly it still didn't work. Current navigation was fine but the Global navigation showed tabs for everything that was in Current navigation. Trying to edit the GN in Site Settings>Navigation had no effect and I couldn't delete the tabs either.

I found that before running the conversion I had to modify the source site's navigation to stop it inheriting global navigation from it's parent site. After that everything ran smoothly!

Thanks again and keep up the good work!

Anonymous said...

After importin getting the below error.

Progress: De-Serializing Objects to Database.
Progress: Importing Folder /_catalogs/masterpage/Forms/Page Layout.
FatalError: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Deployment.ContentTypeSerializer.GetContentType(SPCon
tentType sourceContentType, ImportObjectManager importObjectManager, Boolean isP
arentSystemObject)

Gary Lapointe said...

That's an issue with the content deployment API. My suggestion would be to get in touch with Microsoft support and see if you can get the Content Deployment QFE Pack (see my last blog post).

george.mougos said...

Hello Gary, I have a question regarding the use of your gl-convertsubsitetositecollection. As you can see below I'm trying to use it but get the error message listed below. Any help would be greatly appreciated. Thank you for providing the SharePoint community with these extensions!

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsa
dm -o gl-convertsubsitetositecollection -sourceurl http://s3w06096:9550/ykl0/cas/wssadmin
-targeturl http://s3w06096:9550/ykl0/wssadmin -createmanagedpath -incl
udeusersecurity -owneremail george.mougos@rbc.com

Could not load file or assembly 'Microsoft.SharePoint.Publishing, Version=12.0.0
.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies
. The system cannot find the file specified.

george.mougos said...

A shortfall with the gl-convertsubsitetositecollection extension which you have mentioned is that you have to provide the owner email, logging, name etc. This in my case is devastating since I need to upgrade 1000 subsites into top level sites. Is there something that can help me with this instead of having to manually go into every subsite and pick up this information. Thank you in advance.

Gary Lapointe said...

George - the error you describe typically only occurs if you are not using MOSS but rather WSS. If you are using WSS then you can just use the built-in export/import commands (at least according to MSFT - I haven't tested it myself) - if you are using MOSS and you're getting this error then I suggest you do a repair install.

Gary Lapointe said...

1000 site huh? - that's something - I'd suggest you use PowerShell for this - you can then query the information you need and then pass it into the command.

george.mougos said...

Thank you for getting back so fast Gary. I am using WSSv3 and not MOSS which would explain as you said the error. Once again thank you!

Samer said...

Gary,

Hello again. In running into this using STSADM, I do have some of the Fantastic 40 templates loaded and I do have the GUID error on export. So I deactivated the Fields and Content Types feature on my site prior to attempting the export. No dice. The error DOES seem to originate with the .ParseLookups() method as you suggest. I've also seen other posts elsewhere that I should open FIELDS.XML (in TEMPLATES\FEATURES\TSATYPES) and remove all the "{ and }" and replace them with just quotes. Any thoughts? Can you respond over eMail if possible (samern@ix.netcom.com)?

Anonymous said...

OK, I am getting the following error message when attempting a repair site collection

Failed to find the XML file at location '12\Template\Features\fcgroupslist\feature.xml'


I do not have an fcgroupslist directory under features. Where is that coming from?

Gary Lapointe said...

Most likely there was a feature deployed at some point with that name and the site you have still has a dependency on that feature. The site may actually work just fine with that folder deleted if there was nothing in the folder that it needed to reference back to but when the repair code runs it tries to activate any features that should be active based on your source (assuming you are providing a source - if not then it's failing because it's trying to access a file such as a list definition or something (not directly of course - rather sharepoint is trying to access it)).

Chris O said...

First...really cool stuff.

I have tried both the the commands with the same results. The site is working and accesable but is in a different farm. Is that an issue?

The Web application at http://iwfe01:10801/ops/helpdesk could not be found. Veri
fy that you have typed the URL correctly. If the URL should be serving existing
content, the system administrator may need to add a new request URL mapping to t
he intended application.

Gary Lapointe said...

Check your AAM (alternate access mappings) settings. Are you using host headers? How did you create the web app (via the browser or using my createwebapp command)?

Chris O. said...

Since the issue appears to be with farm 1, I will start there.

The farm 1 source site on iwfe01 is not using any host headers or AAM's but it is using a port. The site and subsite create via broswers with sub-site in question using the Help Desk Fab 40 template. I am running the stsadm command from farm 2 and I have not installed the new commands in farm 1. Both farms have sp1 on and farm 2 has the new infrastructure updates applied.
http://www.harbar.net/archive/2008/07/15/Infrastructure-Updates-Available.aspx

chris o said...

Since the problems appears to be from the source server, I will start there.

It is not using host headers (that is why there is a port) and the sub site was created via fab 40 template. I am running the stsadm command from farm 2 (target) and the new commnands are NOT on farm 1. There is not a problem with getting to farm 1 from farm 2. Both farms have sp1 installed.

Not sure if this answers your question.

chris oneslager said...

I am taking a step back before I try to "upsize" and am having problems. I am trying to backup from one farm and restore to another farm and everthing seems to be good except one thing. Any list that I used custom fields on do not work in edit/add mode nor can I configure them in the list...both throw useless errors. Once I get this working, I can use the command within the same farm and see what happens.

Thanks

Gary Lapointe said...

I think I'm following what you're saying - let me restate something so that I'm sure - you are running my custom command from farm 2 and are trying to access a web application which exists on farm 1? If that's correct then you can't do that - you have to run the commands from a machine that is a part of the farm in which you are trying to affect. So if you're using the convert... command what you'll need to do is instead use the import/export commands and then run the repair... command on the target server.

Gary Lapointe said...

By custom field, do you mean custom field types or just a new field using OOTB field types? If custom field type then make sure that you've installed those on the target server. Also - best practice for moving sites from one server to another is to use stsadm's import/export commands.

chris o. said...

Ok, so I cant do it across farms.
Yes it is a custom field type , not OOTB and I have installed them and they work fine on new list or even adding to an existing list, but the existing one do not work. I am assuming there is something registered differently when the new custom fields/solution are added to the farm which is why the existing fail but the fields do work on new list. Ok, a bit of topic but still a backup/restore issue.

I was going to use import/export but read something that guids change and it will "mess things up". Will you fix sub site stsadm comand handle that?

BTW, thanks. I just find this site and I am sharing with my SPUG today!!!!

Gary Lapointe said...

My repair command will attempt to fix several of those issues. I've also got a custom version of the import command (gl-import2) which adds a -retainobjectidentity paramter which allows the import to occur while keeping all guids the same - note that there are a lot of circumstances where this won't work - best thing is to just give it a try.

chris o said...

Thanks for the feedback. I will use your commands to covert sub-site to SC after I get the restore to the new farm done.

The problem with my custom field was an url attribute that was part of the definition and it was pointing back to the old farm and was getting a null object reference. Once we fixed that we could reconfigure the url to point to the new farm and all is good.

Thanks and sorry about the wild goose chase.

chris o said...

Sorry the extra post but it appears you can catch them. What appears to happen is somewhere in the conversion process the [[page]] link for the wiki converted to an href url which is not good. I checked my backup/restore which is looks good so it appears to have happened in the gl-convertsubsitetositecollection. I am going to try just and export/import and see what happens.

Heiko Hatzfeld said...

Hello,

first of all thanks for all those nifty commands. I love them, and they already saved me a bunch of time.

But I am having a slight Problem with the "Convert a Sub-site to a Site Collection" operation.

It seems to be working fine, but when I get to the point where it will repair the new site after the import, it will fail with a

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

and just do nothing.

The owner of the new site is currently a farm admin, and stsadm is also executed as a farm admin.

Any help would be nice

Thanks a lot in advance

Gary Lapointe said...

Not sure why you're getting that error. You might want to try and download the source and install the debug version which will give you the stack trace for the error which "might" help to find a solution to it.

Anonymous said...

You are the best. This was very helpful. I was going crazy with the page layout issye

Aaron Ferguson said...

Following "Repairing imported site..." I get the error: "
StartIndex cannot be less than zero. Parameter name: startIndex".

Then when browsing to the site (a Team site with Publishing enabled) I get: "An error occurred during the processing of /its/_catalogs/masterpage/default.master. Unknown server tag 'PublishingNavigation:PortalSiteMapDataSource'."

Any ideas?

Gary Lapointe said...

Aaron - if you download the source and deploy the debug build then re-run the command (or run the gl-repairsitecollectionimportedfromsubsite command) it should output the stack trace which will help me troubleshoot the startindex error. As for the other error - that suggests some other issue with your environment - specifically it suggests that the publishing dll isn't there.

Aaron Ferguson said...

Gary - thanks for the reply. I downloaded the full source package, deployed from there and re-ran the "gl-convertsubsitetositecollection" (my previous version didn't have the "gl-" commands only ones without??) which seems to have fixed the first problem.

The problem with the second issue came to me when I remembered I had implemented making sub-sites inherit their navigation from their parent (http://makingoffice2007work.blogspot.com/2007/12/sharepoint-how-to-make-navigation.html) some time ago (thus the reference to "PublishingNavigation" in the site collection default.master).

After fixing that I was nearly there but I see problems on some pages with references to lists etc that no longer exist (coz they are on the old site collection!). Yet another issue to address?...

Gary Lapointe said...

yeah - if you had a version without the gl- then you were about 9 months and about a hundred builds behind :). As for the references to other lists - I'm assuming list view web parts or content query web parts or something like that? Not sure if there's anything I can give you to address that during the migration but if you can provide more details I might be able to point you to something.

Aaron Ferguson said...

Gary - yes its List View and Content Query webparts that are affected. Thanks but I probably just need to plough through and change these manually. It does seem that the whole concept of copying sites around is somewhat fraught with difficulty and you seem to have swatted most if not all of the problems! Cheers.

Justin Torkelson said...

Great tool but I hit a glitch. I'm importing from an exported file and it seems to have imported several sites just fine but it always errors out on the same site:
Value cannot be null.
Parameter Name: g

What's Parameter 'g'?

Thanks again for this tool. you saved me soooooo much work/time.

Gary Lapointe said...

Justin - looks like a value being passed into a new GUID constructor but I'm not sure if it's with my code or the deployment API. If you download the source you can deploy the debug build which should output a stack trace - this will help to identify where the issue is and whether or not it's something I can fix.

Justin Torkelson said...

Gary -

Thanks a lot for the direction. I kept troubleshooting it and found the issue. I found that it wasn't your extensions as much as it was two of my "corrupt" lookup columns that I was trying to import. Thanks again for your time. These extensions are genius.

Lewin said...

Used your import2 stsadm command and it ran great but could not login to the new site collection. Any thoughts?

Frank Mbanusi said...

Gary,
I read some of the above threads regarding site collection to subsite creation. I'm trying to help a client with this issue. Here is what they are doing:

I use the following command to export a site collection without errors:

STSADM -o export -url "http://webapp1.healthsouth.com/sites/testabc" -filename "D:\testabc.cmp" -includeusersecurity

Next, I run the import command below:

STSADM -o import -url "http://webapp2.healthsouth.com/sites/something/testabc" -filename "D:\testabc.cmp" -includeusersecurity

Usually, the import command works flawlessly. However, I ran into two websites that gave errors. I have tried numerous templates and numerous times on multiple servers, but keep receiving the same error after running import command listed below:

[10/20/2008 1:46:01 PM]: FatalError: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFileCollection.get_Item(String urlOfFile)
at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)
at Microsoft.SharePoint.Deployment.ContentTypeSerializer.CreateContentType(SPContentType sourceContentType)
at Microsoft.SharePoint.Deployment.ContentTypeSerializer.ProcessContentType(SPContentType sourceContentType, String contentTypeXml, ImportObjectManager importObjectManager, Boolean IsParentSystemObject)
at Microsoft.SharePoint.Deployment.ListSerializer.UpdateListContentTypes(SPList list, Dictionary`2 listMetaData, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.ListSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()

The only thing that is different on these two websites that I can find is that Variations (different languages, versions, etc.) are turned on at the site collection. Any ideas?

Gary Lapointe said...

It looks like it's having an issue trying to find the document template associated with the content type. Take a look at the exported manifest.xml file and see if you can find what the path is to the template it's trying to set - you might have to tweak the xml (or reset the template on the source and re-export). Also - if you can try and get the infrastructure update deployed (if you haven't already) - there's lots of fixes for the content deployment stuff (not sure if this is one of them though).

fromonesource said...

Gary, can this be done in place? Can a web named /projects be converted into a site collection at the same location named /projects? This would require a managed path and a site collection to be created, does your code do this?

Gary Lapointe said...

You can do it by using export/deleteweb/addpath/createsite (no template)/import/gl-repairsitecollectionimportedfromsubsite.

Karel Heck said...

Hi Gary,

This is excellent work, but unfortunately I am in the same boat as Tim - trying to convert subsites from one farm to site collections in another. I tried running the repair command on the new site collection but it still says "The web application at (old farm) could not be found". Is there any way around this?

Thanks!

ScottP said...

Gary,

Thanks for your contributions to the SP community! I'm having a bit of trouble and hope you can help. I have a sub-site in a site collection that I am trying to move to its own site collection. The site has serveral workflows built in SPD associated with it, a couple lists with event handlers, and a custom web part. When I try to covert it, the command seems to run fine until the import where I get the following:

[2/4/2009 3:16:40 PM]: Progress: Importing File SYSCON Followup Reports/Forms/Upload.aspx.
[2/4/2009 3:16:40 PM]: Progress: Importing File SYSCON Followup Reports/Forms/WebFldr.aspx.
[2/4/2009 3:16:43 PM]: FatalError: Value cannot be null.
Parameter name: g
at System.Guid..ctor(String g)
at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.FixLookupFieldSchema(XmlNode fieldNode, Guid parentWebId, Guid fieldId)
at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.CreateField(SPWeb web, SerializationInfoHelper infoHelper)
at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()

I checked all the lookups in the source site's lists and they all look fine. Any help figuring this out will be greatly appreciated since I have several sites that need to be moved in a similar manner.

Gary Lapointe said...

Karel - I assume you're using the repair command on your new farm and not using an URL from your old farm (so you don't want to use your old farm as the source - use a site collection that reflects your old farm (same configuration) but is on your new farm). The API cannot access web applications on a different farm.

Gary Lapointe said...

Scott - lookup fields are one of those things that the content deployment API just doesn't handle very well. One thing you might consider trying is using the stsadm export command and my gl-import2 command and use the retainobjectidentity flag - there's several caveats to using this but in general it will either work or it won't so it's easy to test. If you do manage to get the import to work then you can just run the gl-repairsitecollectionimportedfromsubsite command. Also, make sure that you at least have the Infrastructure Update installed in your environment - there's several bug fixes related to content deployment.

Cyberpine said...

Great work and very relevant topic.

I'm yet to use your Utility, but suspect I'm going to need to.

For now, I'm not even sure if it will help get us past where we are stuck.

We have this subsite that we need to migrate to a new server in it's own site collection. The site template is Application IT Team workspace.

We export with version 4, but when we attempt to import, we get this on the bugs list:

[3/5/2009 6:12:55 PM]: FatalError: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at Microsoft.SharePoint.Deployment.ListItemSerializer.GetLookupInfoFromFieldData(Object value, Guid& lookupListId, Int32&

Thanks for any help or information!

sales(at)cyberpine(dot)com

Gary Lapointe said...

Unfortunately the application templates (Fab 40) can't be imported due to some craziness that msft does with the site definitions - they basically violate the schema definition by hacking list and lookup values which the content deployment API can't handle - if you search around I think there are some folks who have found workarounds - I've not looked recently though.

booyahman said...

Gary,

first off, good job. I am trying to move a subsite to its own site collection, but running into a problem during the import phase.

I should clarify that this subsite and the new site collection are all on the same farm. It was also originally set up for FBA (Forms Based Authentication) but I have switched it back to Windows for the import/export due to me receiving errors with the -ownerlogin parameter of the command.

This is what I see as the last steps in the log, but frankly, I am clueless as to what it's trying to do at this point, other than trying to import the content. It appears to have brought over all users and roles correctly. Any ideas of what to look at?

[3/25/2009 2:36:56 PM]: Progress: Starting content import.
[3/25/2009 2:36:56 PM]: Progress: De-Serializing Objects to Database.
[3/25/2009 2:36:56 PM]: FatalError: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Deployment.RolesImport..ctor(ImportStreamingContext context, SPSite site, SPWeb web, XmlReader xr, Int32 iBatchSize)
at Microsoft.SharePoint.Deployment.SecurityObjectSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObjectDirect(Object objParent, Type objectType)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()
[3/25/2009 2:36:56 PM]: Progress: Import Completed.
[3/25/2009 2:36:56 PM]: Finish Time: 3/25/2009 2:36:56 PM.
[3/25/2009 2:36:56 PM]: Completed with 0 warnings.
[3/25/2009 2:36:56 PM]: Completed with 1 errors.

Gary Lapointe said...

That would be an issue with the content deployment API - do you have at least the Infrastructure Update installed?

Will said...

Great stuff Gary, we've used several of your extensions, and really appreciate it. A couple of issues though I'd like to ask you about. 1) I'm getting a message that "The file "_catalogs/masterpage/file.aspx" is checked out or locked for editing by Sharepoint\system" when using the gl-repairsitecollectionimportedfromsubsite. The problem appears to be occurring at line 571. It's trying to do a file.Checkout() on the layouts but they are already checked out from when they were added to the _catalogs/masterpage directory.

I tried to setup the project in VS2008 and start the debugger, but had trouble getting the debugger symbols to show, and could not get attached to the process. Do you have any documentation on how to do that.

Thanks for your help and your stuff is awesome. Really appreciate it.

Gary Lapointe said...

To step through the code just build the debug build of the source (depending on your OS and whether gacutil is installed you might have to manually GAC the built dll). Then just run the command with the -debug switch - it will launch the debugger for you.

Anonymous said...

Gary,

I was able to successfully run your utility and created site collection.
What i was not able to get is that are you generating any file while export and import process.
What is the background process for the same?
Please let me know.

Gary Lapointe said...

I'm not entirely sure what you are asking about but if you are wondering if the export generates files that are then imported, then yes - that is true. There is no background process for handling these files though.

Anonymous said...

Gary, thanks for your quick reply.
But what i wanted to know is that where are the export files generated? What is the path to check for the generated files?
I am not getting the generated files. Can you please tell me?

Anonymous said...

Also relating to the above comment, what is the name of the generated file?

Anonymous said...

Gary, do you have any idea about host named site collection.
If yes, can you explain about the same via commands (full procedure).
Also how to get/create multiple root level site (not inside sites) over a single web application?

Gary Lapointe said...

It puts the files in the local temp path (so on win2k8 it would be something like "c:\users\[username]\appdata\local\[#]"

Gary Lapointe said...

The name will be a random GUID.

tripwire said...

Hi Gary, as usual your custom commands have managed to save my life.

My test scenario worked briefly with the exception of a failed feature which I simply activated on the destination site collecton.

Now, for my production scenario I have a few other requirements and am hoping you can provide the right sequence of commands and parameters.

We have a team site (publishing enabled) with several subsites which has grown to almost 15GB. I want to re-provision this as the root site in a clean webapp at e.g. teams.mydomain.com.

As an added bonus I'd also really, really like to give it it's own content database.

Can this be managed do you think? Perhaps adding a -newcontentDB flag to this command would be an asset in this situation?

I look forward to your comments.

Gary Lapointe said...

Use the stsadm createsiteinnewdb command to create the site collection but don't specify the site template. You should then be able to use this new sc as the target in the convert command.

Ricardo said...

Hi Gary,

I have to do this for a couple of WSS 3.0 subsites that I want to turn into top-level sites. Will it work ? If not, do you know the best way to do it ?

Thanks

Gary Lapointe said...

Yes, you can use this command to do what you want though for straight up WSS sites (non-publishing sites) you don't need it (you can use stsadm export/createsite/import to do what you want (don't specify the site template on the createsite). My command will just save you some steps. If you want to use mine I suggest you wait a couple hours and download the latest (I have an updated build that I'm about to push out that removes the database access calls and improves a couple other minor things thus making the command fully supported now). I'll post something via twitter when I've pushed the build out.

tripwire said...

Hi Gary,

Sorry, I don't do Twitter. :) Was this upgraded so as to be a supported approach?

If so, do I just download and upgrade the MOSS Only STSADM Extensions (x86, x64) commands file?

tripwire said...

Sorry, I meant the WSS solution. :\

Gary Lapointe said...

Yup - it's been updated. Just download the MOSS version and redeploy.

Gary Lapointe said...

Right - just download the one for your environment.

tripwire said...

Hi Gary, just running the latest version of gl-convertsubsitetositecollection (say that 3 times quickly) and it's asking for the createsiteinnewdb or createsiteindb parameter.

Looks like you added these in after all! Thank you. That's anothr step taken care of. :D

tripwire said...

Hmm. Either I've done something silly or the createsite parameters need to be called first.

Everything looked good until the creat site moment.

8<--

stsadm -o gl-convertsubsitetositecollection -sourceurl "https://server/restore" -targeturl "https://server/path/new" -nofilecompression -owneremail me@work.com -ownerlogin domain\me -createsiteinnewdb -databasename "newdb"

Exporting site...

Site exported.

Creating site for import...

Another site already exists at https://server/path/new. Delete this site before attempting to create a new site with the same URL, choose a new URL, or create a new inclusion at the path you originally specified.

Error occured creating site.
COMMAND: -o createsiteinnewdb -url "https://server/path/new" -owneremail "me@work.com" -databasename "newdb" -ownerlogin "domain\me"

--8<

Now I definitely didn't create the site in advance. Investigation revealed that a blank collection was created at the specified path. A new content DB was also created but the site wasn't created in it.

I then deleted the new collection (properly) and used the -createsiteindb parameter to see if I can get it created where I need it.

Success! A few settings tweaks and I have a new site collection in specified database from a subsite with publishing enabled.

tripwire said...

OK. I've been through every site setting and the only thing retunring an error is the page-level settings.

I can't seem to resolve this with the usual pagecontact or layoutpage fixes and there's very little on the Web.

Any advice appreciated.

8<--

Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at Microsoft.SharePoint.Publishing.PublishingWeb.GetAvailablePageLayouts()
at Microsoft.SharePoint.Publishing.PublishingWeb.GetAvailablePageLayouts(SPContentTypeId associatedContentTypeId)
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.PageSettingsPage.GetAvailableLayouts()
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.PageSettingsPage.LoadLayoutValues()
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.LoadValues()
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.PageSettingsPage.LoadValues()
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.BasePageSettingsPage.OnLoad(EventArgs e)
at Microsoft.SharePoint.Publishing.Internal.CodeBehind.PageSettingsPage.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Gary Lapointe said...

Not sure why you got the error with the creating a new db but I'll see if I can figure it out tomororw. The other error is specifically related to the direct db access code that I removed - if you have SP2 it should work for you (compromise was to leave it in and deal with support issues or pull it and expect SP2). If you have SP2 then I'll have to research more - it worked in my testing. With SP2 make sure the PublishingResources feature is activated (if you install SP2 just re-activate this feature). Essentially the problem is that the ContentType field in the masterpage library should be a Choice field but it comes through as a Text field pre-SP2.

tripwire said...

Hi Gary, we're running 12.0.0.6421 which I believe is SP2.

I can't find a feature specifically named Publishing Resources.

The 'Office SharePoint Server Enterprise Site Collection' feature was already enabled at the site collection level.

And I also enabled Office SharePoint Server Publishing at the site level. However the error persists.

The Pages library didn't inherit our custom content types. This in itself was no big deal but I wonder if it's related at all?

Gary Lapointe said...

That version is SP2. PublishingResources is hidden - you'll have to go to the command line and use stsadm to activate it (it should be activated by one of the features you mention though (can't remember which)). What site def was your source sub-site and source root site collection based on?

tripwire said...

HI, OK. I found that feature and other hidden ones using SWAT. Yes, I believe it woul dbe activated by the other publishign features as well.

The template was STS#1 team site.

I only specified a sub-site as the sourceurl, not a model site collection. I thought this was an option or did I misread that??

Gary Lapointe said...

The code will take the site collection of whatever source URL you specify (so if you specify the source URL as a sub-site it will look up the chain to the root site collection to get any needed resources.

tripwire said...

It inherites resources? That's brilliant. The beauty iof your solutions always lies in the elegance.

Incidentally, disregard the Page content types issue. I forgot to apply them first at source. :*

Looking forward to any updates on the Page Settings error. In the meantime I'll keep digging.

Gary Lapointe said...

Not so much inherits as consumes (though in regards to content types inherits is correct). There are some publishing features that are scoped at the site collection level - sub-sites may be dependent on those features existing (think page layouts for example). So when you convert a sub-site to a site collection you have to make sure your new site collection has all the dependent assets from the source site collection. If you could let me know what site template the root of your site collection is using then I will see if I can reproduce the issue (if you download my code and uncomment the db access code in the repair command then it should fix the issue but I'd like to work with you to figure whats going on so that I can leave that code commented out.

tripwire said...

Hi Gary, tahnks for your continued support. Site details are as follows.

sts#1 = Subsite used as sourceurl
sps#0 = Site collection parent of sourceurl

Destination site correctly uses the team site template.

I'm wondering if it mightn't be easier to start again.

- Create new SC using sts#1 and use this as the sourceurl "model site collection".
- Add the -exportedfile paramater and point to a CMP of the team site.

Is this the intended use for this parameter?

Gary Lapointe said...

Yup. So I'm assuming you activated the publishing features on the source sites?

tripwire said...

Yes, all required features were enabled. Wish I could give you RDP access. :)

Please let me know if you would prefer to take this offline and I can email through any screenshots or other settings info that might help.

Gary Lapointe said...

Offline would probably be better - you can get my email via the "Contact" tab at the top of the page. I don't suppose there's a chance I could get a backup of your source site collection (minus any confidential data of course)? Also, can you get me the schema for the ContentType field of the masterpage gallery (you can use SharePoint Manager 2007 to pull that info). I've setup my environment to match the info you've given me so far and I've yet to be able to reproduce the problem...

tripwire said...

Hi Gary, it's been a few weeks since I performed my site promotion and I've run into a curious issue.

Neither of the subsites promoted to site collections are getting synched with the SSP and My SharePoint Sites list.

I've checked the logs and the errors seem to point back to the new databases they were created in.

User Profiles Synch WebApp [myWebApp] to Content DB [myContentDB] - Failed

ProfSynch: The site with ID 8bf9c44e-ccf2-46dc-9631-bdc9da7977d9 cannot be synchronized due to an unprovisioned root web
at Microsoft.Office.Server.UserProfiles.SiteSynchronizerCollection.GetSynchInfoForSite(SqlDataReader dr, SynchInfo info)
at Microsoft.Office.Server.UserProfiles.SiteSynchronizerCollection.<get_Elements>d__0.MoveNext()

And an error for every form view in the new sites. e.g.

w3wp.exe (0x2B1C) 0x29D8 Windows SharePoint Services
General 8kh7 High
There is no Web named "/[myNewSite]/Shared Documents/Forms/AllItems.aspx".

Could this be related to running this command or do I have another problem?

vijay said...

First of all thanks for providing such nice stsadm extensions...

However when I try to use gl-convertsubsitetositecollection, it throws an error as below...

Any help is much appreciated...

Note:- I am trying to create sitecollection on a blank webapplication.

Error: The file cannot be imported because its parent web /intranettest does not exist.
[8/13/2009 4:50:10 PM]: FatalError: The file cannot be imported because its parent web /intranettest does not exist.
at Microsoft.SharePoint.Deployment.FolderSerializer.GetParentWeb(SerializationInfoHelper infoHelper, ImportObjectManager objectManager)
at Microsoft.SharePoint.Deployment.FolderSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serializationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()
[8/13/2009 4:50:10 PM]: Progress: Import Completed.

Michael Nemtsev said...

Hello,

how can I use stsadm –o gl-repairsitecollectionimportedfromsubsite

for the existing site, when I don't want to re-import it again.

do you provide any extension to fix error without making another stadm import?!

I'm asking because client made a lot of customizations and they want to fix existing problem without reimporting it

Gary Lapointe said...

The repair commend doesn't re-import.

syates21 said...

Thanks for all your contributions to the overworked SharePoint admin community Gary. :) I had one question about the custom stsadm command. Does it bring the entire user information list over from the "source" site collection to the new one when you move a subsite? If so, is there a way to get it only to bring users specifically listed on the ACLs for the subsite? This would be a huge win for us in trying to split up an overgrown site collection with a nightmare of a user information list.

Aniket said...

Man Uyou are really made my day worth. Thanks alot for this command it save me from so many hecks. i had the dev environment with sp2 and prod sp1 i have to move the site coolection and your command works like a charm i ahd back up the site collection and restore it as subsite using SPD and then convert that site using ur command it works awesome.
Thanks for this great utility.
Cheers!!!!!!!!!!

Gary Lapointe said...

I believe it will bring all users over - this process is controlled by the content deployment API and nothing specific that I'm doing so there's not much I can do to fix it. You'd have to clean up the users before migrating.

stressed said...

this tool sounds amazing and is just what I need, problem is my site is in hebrew (that is rtl under 1037 directory) and it seems to be causing problems already in the beginning of the process, just to give you a clue this is the first error I get when running your command: Feature 'd8d8df90-7b1f-49c1-b170-6f46a94f8c3c' for list template '1104' is not installed in this farm. The operation could not be completed.
Error occured exporting site.
COMMAND: -o export -url "http//source" -includeusersecurity -
versions 4 -quiet -filename "C:\Users\administrator.MYDOMAIN\AppData\Local\Tem
p\3\7139722f-676c-4f2e-aace-c6e2f88d86aa"

do you have any idea as to why this is happenning? any help would be greatly appreciated!

Gary Lapointe said...

Looks like you have a custom feature that's been uninstalled without being deactivated from the site. You'll need to re-install the feature or try and deactivate it.

stressed said...

thanx for the fast reply - you were right. now I managed to fix that and ran ur command it did the export but then fell when trying to create a site in the location I specified, it said I first had to delete the site. so I went to the site and deleted it but then I had to continue running the commands manually, everything worked until the import command it took me a while to find the cmp files once I found them it keeps on giving me a "The directory "c:/XXX" does not exist" error - do you think you know why? have I missed something?
again I thank you for your time and help

Gary Lapointe said...

It would end up running the export again but you can just run the convert command again (or pass in the path the exported files into the convert command and it will use that instead of exporting again). As for the error - just make sure you have the path to the directory correct and that you are property setting the nofilecompression parameter.

Anonymous said...

Gary:

A simple heart-felt Thank You! from all of us learners.

Anonymous said...

Hi Gary:
What steps can I take to figure out where I am going wrong?

All I get from stsadm is: 'Command Line error' along with a listing of the -o commands including the gl- list, and example usage.

My command looks like:
C:\>stsadm -o gl-convertsubsitetositecollection -sourceurl http://xxxx.zzz.com:
5500/ZX/ -targeturl http://xxxx.zzz.com:7500/ -createmanagedpath -nofilecompre
ssion -owneremail niceguy@greatco.com -ownerlogin aDomain\xtAdmin -createsitein
db -databasename WSS_Content_DB2

Thank you.

Kocyc

Anonymous said...

Dont need to all this.
Simply Deactivate and reactivate Site Publishing Features under Site Administration->Site features->Office SharePoint Server Publishing[Deactive first and then Activate].

--Avinash.Devkate--

Alan said...

I am running into some of the issues with subsites imported to site collections. I cannot run the gl_repairsitecollectionimportedfromsubsite successfully on any site imported in this manner. I experience three different errors:

Some hang at:
Progress: End fixing page layouts and site templates

Some crash at:
Progress: Importing List Master Page Gallery
FatalError: Cannot complete this action

Others crash at:
Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
Please try again
at Microsoft.SharePoint.Library.SPRequest.SetListContentTypes(...

Is there anything I can possibly do to get this command to run without these errors?

Gary Lapointe said...

Unfortunately there's just not enough information for me to help you. Your best bet would be to debug the code using Visual Studio and see what's happening (the code works for me in my test cases).

Anonymous said...

Hey Gary - it's jason kaczor here, I am getting the exact same behaviour - hang with no errors. Unfortunately this is a production environment - no debugging. MOSS x64, SP2, Dec 2009 CU.

Gary Lapointe said...

Does anything come through in terms of logs (console output, ULS, event log)?

Kelvin said...

Hi Gary, i am using the gl-convertsubsitetositecollection command. Does this command use any temp space in C:\? After running this command, my C:\ space was reduced dramatically. Thanks.

Gary Lapointe said...

Yes - the exported site is stored in a temp path on the root. You manually export the site and use the exportedfile parameter to use those files rather than have it export and save to the root.

Kelvin said...

Hi Gary, will the exported site in the %systemroot%\temp be automatically deleted after the import?

Strange, I have use the -exportedfile parameter, and my C:\ space was reduced also.

Gary Lapointe said...

I chose not to delete it in case the user needed to retrieve the exported files. As for the space still being taken up - it could be from the ULS logs, the exported site is all I put on disk so if you're using the -exportedfile param then I'm not directly writing anything.

Kelvin said...

Thank Gary for the response. Well, if I want to delete away the exported file in C:\ to free up space, where exactly is the path? I can't seem to locate it in C:\temp or C:\windows\temp. Thanks very much.

Gary Lapointe said...

It will be in the current users local temp folder.

Steve Hahn said...

Great tool. Now if I can only get it to work. :)

I get:

Progress: Begin adding missing features...
Progress: Activating site scoped feature "Reporting"..
Progress: End adding missing features.
Object reference not set to an instance of an object.

Command:
stsadm -o gl-repairsitecollectionimportedfromsubsite -sourceurl -targeturl

Doesn't seem to matter what source website I choose.

Gary Lapointe said...

If you have SharePoint dev machine can you rebuild the project in debug mode and re-deploy? This will give you a stack trace which I can use to, hopefully, fix the issue you're seeing.

DavidLewis27 said...

Gary I am getting the same error as steve. I tried to rebuild your project but I am getting errors. I will see if I can work through them

Gary Lapointe said...

If you're able to get me any more specific information (stack trace or something) then I'll try to work with you guys to fix it.

DavidLewis27 said...

Not sure why it is giving me warnings on my references but here is my output when I try to rebuild.

Error 1 An error occurred while validating. HRESULT = '80004005' E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.PowerShell.Commands.Setup\Lapointe.SharePoint.PowerShell.Commands.Setup.vdproj Lapointe.SharePoint.PowerShell.Commands.Setup
Error 2 An error occurred while validating. HRESULT = '80004005' E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.PowerShell.Commands.Setup64\Lapointe.SharePoint.PowerShell.Commands.Setup64.vdproj Lapointe.SharePoint.PowerShell.Commands.Setup64
Warning 3 All custom dialogs must precede the 'Installation Folder' dialog. E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.PowerShell.Commands.Setup64\Lapointe.SharePoint.PowerShell.Commands.Setup64.vdproj Lapointe.SharePoint.PowerShell.Commands.Setup64
Error 4 An error occurred while validating. HRESULT = '80004005' E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.PowerShell.Commands.Setup64\Lapointe.SharePoint.PowerShell.Commands.Setup64.vdproj Lapointe.SharePoint.PowerShell.Commands.Setup64
Error 5 The command "cd E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.STSADM.Commands\
Install.bat "E:\Sharepoint Development\Lapointe.SharePoint.Automation\Lapointe.SharePoint.STSADM.Commands\bin\DebugWSS\Lapointe.SharePoint.STSADM.Commands.dll" DebugWSS
" exited with code 1. Lapointe.SharePoint.STSADM.Commands
Error 6 The OutputPath property is not set for this project. Please check to make sure that you have specified a valid Configuration/Platform combination. Configuration='Debug' Platform='AnyCPU' Lapointe.SharePoint.PowerShell.Commands
Warning 7 The referenced component 'Microsoft.Office.Server' could not be found.
Warning 8 The referenced component 'Microsoft.SharePoint' could not be found.
Warning 9 The referenced component 'System' could not be found.
Warning 10 The referenced component 'System.Configuration.Install' could not be found.
Warning 11 The referenced component 'System.Management.Automation' could not be found.
Warning 12 The referenced component 'System.Web' could not be found.
Warning 13 The referenced component 'System.XML' could not be found.
Warning 14 The referenced component 'System.Xml.Linq' could not be found.
Warning 15 The referenced component 'System.Data.DataSetExtensions' could not be found.
Warning 16 The referenced component 'System.Data' could not be found.


Got any ideas why these errors are happening

Gary Lapointe said...

Make sure you build the DebugMOSS configuration. To save you some time I've uploaded the debug build of the dll along with the pdb file here: http://www.thelapointes.com/blog/Lapointe.SharePoint.STSADM.Commands.dll and http://www.thelapointes.com/blog/Lapointe.SharePoint.STSADM.Commands.pdb - just GAC the dll and you should be good.

DavidLewis27 said...

I inserted the dll into the GAC. pdb address was not correct or the file is no longer in that location. but that did not change anything for me

Steve Hahn said...

I was getting all those messages too for my build. ;)

The references worked themselves out...(I first tried to add them all..but then restarted..)

I had to change from ANYCPU and put in X86 - since this is my test environment unfortunately. :)

I then had to make sure PowerShell was set to run scripts (it was restricted) and change a few other settings (unassigned variables...and ad a \x86 to a path...)

What are the next steps after a successful build?

Gary Lapointe said...

Just put the DLL in the GAC - this should be dumping out the stack trace but I'll have to double check to be sure.

Gary Lapointe said...

You don't need the pdb in the GAC (just there for debugging) - I'll try to take a look at the code this week - I thought I had it outputting the stack trace when in debug mode but maybe I'm thinking of a different cmd?

Steve Hahn said...

Here is some more food for thought:

C:\>stsadm -o gl-repairsitecollectionimportedfromsubsite -sourceurl "https://sps-test.cpcc.edu" -targeturl "https://sps
test.cpcc.edu/sites/divisions/its" -debug

Progress: Begin adding missing features...
Progress: Activating site scoped feature "Reporting"...
Progress: End adding missing features.
Object reference not set to an instance of an object.


C:\>stsadm -o gl-convertsubsitetositecollection -sourceurl "https://sps-test.cpcc.edu/sites/divisions/its" -targeturl "
ttps://sps-test.cpcc.edu/sites/its" -owneremail "steve.hahn@cpcc.edu"

Exporting site...

Site exported.

Creating site for import...

An owner login is required since this web application is not in Active Directory account creation mode.




Error Type: Microsoft.SharePoint.SPException
Error Message: Error occured creating site.
COMMAND: -o createsite -url "https://sps-test.cpcc.edu/sites/its" -owneremail "steve.hahn@cpcc.edu"
Error Source: Lapointe.SharePoint.STSADM.Commands
Error TargetSite:Void CreateSite(System.String, System.String, Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPP
ramCollection)
Error Stack Trace:
at Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.ConvertSubSiteToSiteCollection.CreateSite(String sourc
Url, String targetUrl, SPParamCollection Params)
at Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.ConvertSubSiteToSiteCollection.Execute(String command,
StringDictionary keyValues, String& output)
Error occured creating site.
COMMAND: -o createsite -url "https://sps-test.cpcc.edu/sites/its" -owneremail "steve.hahn@cpcc.edu"

(you can contact me directly at the above email)

Gary Lapointe said...

Steve - Provide an ownerlogin parameter for the convert command.

DavidLewis27 said...

immisGary,

Sorry it took so long for me to get you my call stack but here it is.

Lapointe.SharePoint.STSADM.Commands.dll!Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.AddMissingFeatures(Microsoft.SharePoint.SPSite sourceSite = {SPSite Url=http://Dev}, Microsoft.SharePoint.SPWeb sourceWeb = {BPM}, Microsoft.SharePoint.SPSite targetSite = {SPSite Url=http://Dev/americas/test}, Microsoft.SharePoint.SPWeb targetWeb = {Test}) Line 762 + 0x56 bytes C#
Lapointe.SharePoint.STSADM.Commands.dll!Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairSite(string sourceurl = "http://Dev/BPM", string targeturl = "http://Dev/americas/test", bool verbose = true) Line 103 + 0x15 bytes C#
Lapointe.SharePoint.STSADM.Commands.dll!Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.Execute(string command = "gl-repairsitecollectionimportedfromsubsite", System.Collections.Specialized.StringDictionary keyValues = {System.Collections.Specialized.StringDictionary}, out string output = "") Line 82 + 0x12 bytes C#
Lapointe.SharePoint.STSADM.Commands.dll!Lapointe.SharePoint.STSADM.Commands.OperationHelpers.SPOperation.Run(string command = "gl-repairsitecollectionimportedfromsubsite", System.Collections.Specialized.StringDictionary keyValues = {System.Collections.Specialized.StringDictionary}, out string output = "") Line 222 + 0x29 bytes C#

Any direction on this is appreciated

Raghavendra said...

Hey Gary,

This was a great post. And now I am trying to use this. My requirement is that I need to export 300 sites in 3 site collections (all 3 on 1 web application - say "webapp1") to 300 individual sitecollections(all 300 to the same web application -"webapp1"). Kindly help me on how I can automate it using your stsadm extensions with some custom coding.

Naythan said...

Hi Gary,

I am trying to use gl-repairsitecollectionimportedfromsubsite, as it sounds exactly what I need (breaking 30 subsites in to sites). Unfortunately I am unable to get the command to run. I have even ran a test using your stsadm commands testweb and testsite, to try and minimise the chance of it being a syntax error on my part.

I can run some of the gl- commands, but not gl-repairsitecollectionimportedfromsubsite, even -help gl-repairsitecollectionimportedfromsubsite does not return the help, just "command line error."

Running stsadm -o gl-enumfeatures -url http://sitename works , so I am at a loss as to why repairsitecollectionimportedfromsubsite do not.

Any helpful pointers?

Gary Lapointe said...

Naythan - sometimes the hyphens get mixed up. Make sure you re-type the command by hand, don't copy and paste.

tripwire said...

Naythan, have you actually converted the Web (subsite) to a Site Collection (site) as yet? Or are you trying to run this command on a Web?

If not, you need to run the convert subsite to site collection command first. Only run this command on the promoted site if you run into trouble.

At least I believe that's how it works. Please feel free to correct me if I'm wrong Gary!

Gary Lapointe said...

Raghavendra - you can do this pretty easily with PowerShell. You just need to get the SPSite source site collection, loop through all the webs you want to convert and then call the stsadm command.

jag said...

Took backup of site from one web application and restored as top level site on new web application. Now when i click on Create Page, I gives this error : "data at the root level is invalid. line 1 position 1"

My source subsite is in production. I took backup of that and restored that as site collection in my Test environment. Then when i am trying "create page" i hit the error.

Downloaded and deployed Lapointe.SharePoint.STSADM.Commands.wsp (IN TEST ENVIRONMENT)

Now i have to try the command
stsadm.exe -o gl-repairsitecollectionimportedfromsubsite –sourceurl “url” –targeturl “url”

It is failing saying the source url is not available. I am sure this is because, it cant access the Site in the Production. Can somebody please eloborate more on this and help me ?

Gary Lapointe said...

Jag - if your source site is in a different farm then you need to use a local source site which can be used as a model site - essentially you need a site that has the same basic configuration (same masterpages and pagelayouts and features specifically - it doesn't have to be the same site as long as the site collection contains enough information to help repair the new site collection).

Fernando said...

Hi Gary!

Amazing extensions that you have built!

I'm having some problems with the export and import. I'm trying to export a subsite and import it as a site collection, say from http://urlsite/sitename to http://urlsite/sites/sitename.

Progress: Importing List .
FatalError: Specified method is not supported.
at Microsoft.SharePoint.SPList.set_MajorVersionLimit(Int32 value)
at Microsoft.SharePoint.Deployment.ListSerializer.UpdateListData(SPList list,
Dictionary`2 listMetaData, SPImportSettings settings)
at Microsoft.SharePoint.Deployment.DocumentLibrarySerializer.UpdateListData(S
PList list, Dictionary`2 listMetaData, SPImportSettings settings)
at Microsoft.SharePoint.Deployment.ListSerializer.SetObjectData(Object obj, S
erializationInfo info, StreamingContext context, ISurrogateSelector selector)
at Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType,
Boolean isChildObject)
at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type object
Type, Boolean isChildObject, DeploymentObject envelope)
at Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializat
ionStream)
at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream serial
izationStream)
at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReade
r xmlReader)
at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects()
at Microsoft.SharePoint.Deployment.SPImport.Run()

I've used your extensions and the error stays the same.
I surfed the net and it seems to be that on that list i have to enable versioning, export the site,import the site and everything goes fine...until another list has the same problem, and then i have to start all over again.
Have you ever found this error?I cannot find any solution for this

Thank's

Gary Lapointe said...

That's a new one. Are you running SP2 with the latest CU? Wondering if it's perhaps a bug that may have been fixed at some point?

Papos said...

Hi Gary!

thanks for the quick reply.
I'm only running SP1.
I thought about that also but i find weird that there's not much information about this error on the internet.

Gary Lapointe said...

The infrastructure update came out after SP1 and the bulk of that update was to fix issues related to content deployment. I'd strongly suggest you go to SP2 and see if you still have the issues.

Henk said...

Gary,

I have converted a subsite to a sitecollection. Thet original sitecollection is lcid 1033 en the subsite was lcid 1043. The convert finalized ok, but not all content types and the masterpage definitions were set correctly. Now I have excecuted the command gl-repairsitecollectionimportedfromsubsite and it stops at creating content type System with the error object reference not set to an instance of an object.

Do you have any idea what is the problem I think it is lcid related.

Gary Lapointe said...

Henk - I suspect it has something to do with switching the lcid of the root site but I've honestly never tested this scenario. If you are able to use the debug build of the tool and can get me a stack trace I might be able to fix it.

I honestly haven't had a lot of time to look at some of the issues with the extensions lately (working on a book plus lots of other stuff so I've been unusually bad about making fixes to the tools - hoping to have some time in the near future but for now they're kind of on the back burner for me).

SharePointWale said...

Hey Gary, first off, thanks for your contribs to the SP community, it is greatly appreciated.
I am trying to move a large web to its own site collection in a different content database, the export works okay but I get the fatal exception :
FatalError: Item does not exist. It may have been deleted by another user.
at Microsoft.SharePoint.SPListItem.EnsureItemIsValid()

during the import process, what I would really like to do is to have such errors logged and the import continue...any ideas? Thanks in advance!

Gary Lapointe said...

SharePointWale - unfortunately I'm just using the OOTB content deployment API to do the export and import so I can't control how it handles the errors. I suspect that with this specific issue it is trying to locate something in the root web (from the source) and it's not finding it - perhaps you have a lookup column pointing to a list in the root web (or another peer web) or a list view web part or some other artifact like that.

Anonymous said...

Hi Gary,

We are using your convertSubsiteToSiteCollection and it has saved us lot of custom coding. But we just realized that there is no -versions attribute.

Is the default for versions is 4? Do we export the subsite first and then run command if we want it to be any other version?

Thanks,
Vinita

Anonymous said...

Hi,

is there a way to pipe the exported files to another destination instead to the user profiles temp directory??

Best regards
Knut

Gary Lapointe said...

Just manually export the file and then use the exportfile parameter.

Gary Lapointe said...

I believe that I'm exporting all versions. In any case - if you need more control you can always just do the export/import manually and just run the repair command.

Steve said...

Does this conversion include any alerts that users have setup? I'm working with a business team that needs to have their site converted in this way, but we are trying to make it as transparent to them as possible. Requiring all users to recreate their alerts is not ideal. As a related question - are alerts in any way associated with the site itself, or are they associated with the user profile?

Jas said...

Hi Gary,
Used the verbose command with convertsubsitetosite extension and I am getting this error:

Progress: Setting available page layouts...
Progress: End fixing page layouts and site templates.
The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

The global navigation is not fixed after the import. I installed the wsp on the WFE server. Is this due to setup issues or something else ?

Meanwhile I am trying to go through the code to see which file it is accessing.

Thanks,
Jas

Gary Lapointe said...

Alerts don't migrate (nor do recycle bin items, workflows, and personalization settings). This is a limit of the content deployment API which I'm using to do the migration.

Perry said...

This is throwing a file not found exception for me. Adding printfs has narrowed it down to somewhere inside RepairSiteCollectionImportedFromSubSite:FixPageLayoutsAndSiteTemplates (line 524) I believe. I'm using a version I downloaded today.

Partial traceback:

at Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob.Start(SPWeb currentUserWeb)
at Microsoft.SharePoint.Publishing.PublishingWeb.PushdownInheritanceOfAvailablePageLayouts(Boolean useSynchronous, String succe
ssUrl, String failureUrl, LroWssAreaPropertyPushdown previousJob, Boolean throwExceptionOnFailure)
at Microsoft.SharePoint.Publishing.PublishingWeb.PushdownInheritanceOfAvailablePageLayouts(Boolean useSynchronous, String succe
ssUrl, String failureUrl, Boolean throwExceptionOnFailure)
at Microsoft.SharePoint.Publishing.PublishingWeb.SetAvailablePageLayoutsString(String pageLayouts, Boolean resetAllSubsitesToIn
herit)
at Microsoft.SharePoint.Publishing.PublishingWeb.AllowAllPageLayouts(Boolean resetAllSubsitesToInherit)
at Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.FixPageLayoutsAndSiteTemp
lates(PublishingSite sourcePublishingSite, PublishingWeb sourcePublishingWeb, PublishingSite targetPublishingSite, PublishingWeb t
argetPublishingWeb, SPSite targetSite, SPWeb targetWeb)
at Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairSite(String sourceu
rl, String targeturl, Boolean verbose)
at Lapointe.SharePoint.STSADM.Commands.SiteCollectionSettings.ConvertSubSiteToSiteCollection.Execute(String command, StringDict
ionary keyValues, String& output)
The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Perry said...

I thought at first the problem was that this line (c. 540 in RepairSite...)

if (!string.IsNullOrEmpty(targetWeb.AllProperties["__PageLayouts"] as string))

needed to have targetWeb.AllProperties.HasKey("__PageLayouts") added to it, but not so.

The problem is, as the preceding callback trace showed, that the AllowAllPageLayouts is throwing an exception.

The first solution to occur to me is to add a PublishingWeb.IsPublishingWeb(targetWeb) protecting if block.

Perry said...

AllowAllWebTemplates also throws an exception when called on a non-publishing web; perhaps the entire FixPageLayoutsAndSiteTemplates method is problematic.

Perry said...

The SetGlobalNavigation call probably also needs to be protected, e.g., c l 163

if (PublishingWeb.IsPublishingWeb(targetWeb))
{
SetGlobalNavigation(targetPublishingWeb);
}

Gary Lapointe said...

The bulk of my testing was done with pure publishing sites. "Theoreticaly" migrating non-publishing sites should work without the need for these extensions.

Perry said...

gl-convertsubsitetositecollection finally succeeded, with my fixes described above. They're simple fixes, but I'd be happy to send you a copy if that would help get them fixed in your trunk.

And thanks for making this great software available!

Amores said...

I'd be happy to send you fixed code, or a patch file, but I have no email address. May I send you some fixed code (b/c I'd love to get this fixed in your trunk version)?

Gary Lapointe said...

Feel free to send any corrections. Just click the contact button at the top of the page for the email.

Dan said...

this command is brilliant. you rule dude! the maharajah of all that is SharePoint!

Anonymous said...

I have upgraded a site to a site collection and now cannot create pages. I ran the command gl-repairsitecollectionimportedfromsubsite and it starts fine but finishes with "Index (zero based) must be greater than or equal to zero and less than the size of the argument list."

Thanks,
Ilan

Gary Lapointe said...

Is there any kind of stack trace being output (I can't remember if I had one dumping or not). Most likely the issue is with the page layouts--they're probably just not getting fixed correctly for some reason.

«Oldest ‹Older   1 – 200 of 205   Newer› Newest»