我有一個sharepoint.deployment.spimport comportment的問題。如何使用c#導入SPWeb以具有與PowerShell相同的行爲?
我想在同一網站集中像中複製網頁:
MYSERVER/mysitecoll/WEBSITE1
MYSERVER/mysitecoll/WEBSITE2
當我使用PowerShell命令執行此操作,它完美無缺,網站2與網站1相同
Export-SPWeb -Identity http://myserver/mysitecoll/website1 -Path D:\mybackups\mytestsave\mybackup.bak
和
Import-SPWeb -Identity http://myserver/mysitecoll/website2 -Path D:\mybackups\mytestsave\mybackup.bak
但我需要用C#做同樣的我用
private void ExportSpWeb()
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = SPContext.Current.Web;
SPExportObject exportObject = new SPExportObject();
exportObject.Id = myWeb.ID;
exportObject.ParentId = mySite.ID;
exportObject.Type = SPDeploymentObjectType.Web;
SPExportSettings settings = new SPExportSettings();
settings.SiteUrl = mySite.Url;
settings.ExportMethod = SPExportMethodType.ExportAll;
settings.FileLocation = "D:\\mybackups\\mytestsave";
settings.BaseFileName = "test.cab";
settings.FileCompression = true;
settings.ExcludeDependencies = true;
settings.CommandLineVerbose = true;
settings.ExportObjects.Add(exportObject);
SPExport export = new SPExport(settings);
export.Run();
}
private void importSpWeb()
{
SPSite mySite = SPContext.Current.Site;
SPWeb myDestWeb = mySite.AllWebs["website2"];
SPImportSettings impsettings = new SPImportSettings();
impsettings.SiteUrl = mySite.Url;
impsettings.LogFilePath = "D:\\mybackups\\mytestsave\\test.log";
impsettings.WebUrl = myDestWeb.ServerRelativeUrl;
impsettings.FileLocation = "D:\\mybackups\\mytestsave";
impsettings.FileCompression = true;
impsettings.BaseFileName = "test.cab";
impsettings.RetainObjectIdentity = false;
SPImport import = new SPImport(impsettings);
import.Run();
}
但行爲舉止是不一樣的PowerShell:而不是使用指定的WEBURL設置創建(http://myserver/mysitecoll/website2) , 導入的網站創建爲一個新的子網站與路徑 http://myserver/mysitecoll/website2/website1
如何編輯我的代碼以獲取與PowerShell相同的結果?
做我的回答解決您的問題? – tinamou
您好,首先感謝您的回答,目前,我們已經決定使用「網站定義」,但是,它可能會讓我的企業中的SharePoint專家開發人員感興趣,以獲得答案。 –