I recently had to create some functionality for a customer to take a subsite, and duplicate it for backup purposes. I would normally walk them through the process using stsadm or use Save Site as Template but they wanted a simple method of doing it. I created them a on click solution.
My code is below. We were going to move forward with the SPWeb SaveAsTemplate option but the site was too large. Even after increasing the template size SharePoint still errored. See KB Article 960969 for more details. So instead we are using stsadm and exporting the site then importing it.
Exporting a Site
Process exportSite = new Process();
string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);
string commandLine = " -o export -url " + SPContext.Current.Web.Url + " -filename c:\\" + tempName + ".exp -overwrite -includeusersecurity";
exportSite.StartInfo.UseShellExecute = true;
exportSite.StartInfo.FileName = commonFilesPath + @"\Microsoft Shared\web server extensions\12\BIN\" + "stsadm.exe ";
exportSite.StartInfo.Arguments = commandLine;
exportSite.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
exportSite.Start();
exportSite.Close();
Importing a Site
Process importSite = new Process();
string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);
string commandLine = " -o import -url " + SPContext.Current.Web.Url + "/" + tempName + " -filename c:\\" + tempName + ".exp -includeusersecurity";
importSite.StartInfo.UseShellExecute = true;
importSite.StartInfo.FileName = commonFilesPath + @"\Microsoft Shared\web server extensions\12\BIN\" + "stsadm.exe ";
importSite.StartInfo.Arguments = commandLine;
importSite.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
importSite.Start();
importSite.Close();
Hope this helps! If you have a better method I would love to hear it, I'm always looking for ways to improve!!
416d9bba-44d3-4007-a7f5-7a230e3a9765|0|.0