Wednesday 4 November 2009

Reset All sites to site definition (gosted) Programatically

If you like me need to reset your migrated page to site definition you can:

1) bother yourself with using SharePoint Designer and change the customized page to uncostomized...one by one.

2) go to the site and under site setting click on the "Reset to site definition" where you will be able to reset a site or all the site under a site collection.

3) if you want a quick and reusable solution, create some code using web service model and let the Sharepoint object model work for you. Create a winForm with 3 textbox (txtSiteUrl,txtUsername,txtPassword) and 1 button. Add a web reference (Wss3).Then add the following code

Here is the code:

private void StartProcess()
{
// Declare and initialize a variable for the Lists Web Service.
Wss3.Webs WebsService = new Wss3.Webs();

if (txtSiteUrl.Text != "")
WebsService.Url = txtSiteUrl.Text + "/_vti_bin/Webs.asmx";
try
{
WebsService.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text, "DOMAIN_NAME_OF_THE_USER");

/* Declare an XmlNode object and initialize it with the XML response from
the GetListItems method.*/

System.Xml.XmlNode nodeListItems = WebsService.GetWebCollection();

System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(nodeListItems.OwnerDocument.NameTable);
mgr.AddNamespace("wb", "http://schemas.microsoft.com/sharepoint/soap/");

System.Xml.XmlNodeList nodes = nodeListItems.SelectNodes("//wb:Web", mgr);

foreach (System.Xml.XmlNode node in nodes)
{
string url = node.Attributes["Url"].Value;
ResetToSiteDefition(url);
}

MessageBox.Show("Validation Completed");
}
catch (System.Net.WebException webException)
{
MessageBox.Show("Please, Verify the Credential", "Error StartProcess", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
catch (SoapServerException soapException)
{
MessageBox.Show("Please, Verify the Url", "Error StartProcess", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void ResetToSiteDefition(string url)
{
Wss3.Webs WebsService = new Wss3.Webs();

try
{
WebsService.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text, "DOMAIN_NAME_OF_THE_USER");


if (!string.IsNullOrEmpty(url))
{
WebsService.Url = string.Format("{0}/_vti_bin/Webs.asmx", url);
WebsService.RevertAllFileContentStreams();
}
}
catch (System.Net.WebException webException)
{
MessageBox.Show("Please, Verify the Credential", "Error StartProcess", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
catch (SoapServerException soapException)
{
MessageBox.Show("Please, Verify the Url", "Error StartProcess", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Migrating WSS2 to WSS3

Hi All,

Migrating from Wss2 to Wss3 is always a bit tedious. You go through manuals and instruction and they go quite deep into the ocean. Headacke! I‘ll say.

Anyway, I was migrating from wss2 to wss3 the other day and discover a much quicker procedure.

1 1 Backup your content database used by Wss2 (as a safety measure, and a copy will be used for migration).

2 Restore it into your SQL Server of choice. This could be the current one but you will need, I guess, to rename it somehow.

3 Install Net 3.0 and Wss3 (sp3 if you want) into your Front End server.

4 Download and run the prescan.exe (download if wss3 has not provided it for you) on the box. NOT SURE THIS STEP IS REALLY NEEDED WHEN WSS2 IS NOT INSTALLED ON THE SAME BOX. BUT WHAT THE HEIK!

5 Then create a Web application using the Sharepoint Administrator site.

6 Then use the stsadm addcontentdb:

stsadm -o addcontentdb -url urlToTheWebApplicationCreated -databasename theNameOfYourWss2ContentDatabase -databaseserver theNameOfTheSQLServer –[databaseuser usernameWhohasAccessToDatabase -password passwordOfTheUsername]. (open a window command and go to the bin folder under the 12 hives)

Notice that username and password will ONLY work if the SQL Server Database has allowed mixed login. If it is only Window authentication, DO NOT PROVIDES the username and password as part of the stsadm command.

After adding the content database to your web application successfully, go to your Sharepoint Administrator page and under “application management” click on “Web application list” then click on the created “Web application”. Then click on “Content Database” and remove the content database which has 0 as value of the Current number of sites.

Then that’s should be it fox!
Enjoy!!!

Severin