1
我想使用SPExport(它工作正常)和SPImport複製一個網站到另一個位置。我在Sharepoint Foundation 2010中使用應用程序頁面。此代碼在Button單擊事件上執行。Sharepoint 2010 SPImport.Run安全異常
using (SPWeb web = site.OpenWeb(sourceWebUrl))
{
SPExportSettings exportSettings = new SPExportSettings();
exportSettings.FileLocation = exportPath;
exportSettings.BaseFileName = exportFileName;
exportSettings.SiteUrl = site.Url;
exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.FileCompression = true;
exportSettings.IncludeVersions = SPIncludeVersions.All;
exportSettings.IncludeSecurity = SPIncludeSecurity.All;
exportSettings.ExcludeDependencies = false;
exportSettings.ExportFrontEndFileStreams = true;
exportSettings.OverwriteExistingDataFile = true;
SPExportObject expObj = new SPExportObject();
expObj.IncludeDescendants = SPIncludeDescendants.All;
expObj.Id = web.ID;
expObj.Type = SPDeploymentObjectType.Web;
exportSettings.ExportObjects.Add(expObj);
SPExport export = new SPExport(exportSettings);
export.Run();
}
using (SPWeb web = site.OpenWeb(destinationWebUrl))
{
web.AllowUnsafeUpdates = true;
SPImportSettings importSettings = new SPImportSettings();
web.FileLocation = exportPath;
web.BaseFileName = exportFileName;
web.IncludeSecurity = SPIncludeSecurity.All;
web.UpdateVersions = SPUpdateVersions.Overwrite;
web.RetainObjectIdentity = false;
web.SiteUrl = site.Url;
web.WebUrl = web.Url;
web.Validate();
SPImport import = new SPImport(importSettings);
import.Run();
web.AllowUnsafeUpdates = false;
}
例外「此頁面的安全驗證無效點擊返回在Web瀏覽器,刷新頁面,並再次嘗試您的操作。」當SPImport.Run()被調用時拋出。
我一直沒有找到解決方案,這個問題既沒有在應用程序頁面上添加FormDigest控件,也沒有在目標網頁上允許不安全的更新。
此外,從控制檯應用程序運行此代碼工作正常,但如果代碼從應用程序頁面運行它不起作用(即使提高安全性)。
任何幫助,將不勝感激。謝謝。
祝賀。如果可以,請確保將您的答案標記爲「已接受」,以便其他人可以從您的成功中學習。乾杯〜 –
對於正在提升特權的人員,您需要先執行此操作。 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.validateformdigest(v=office.14).aspx – trgraglia