zoukankan      html  css  js  c++  java
  • SharePOint 2010 编程导入导出站点

    /// <summary>
            /// Exports plant site
            /// </summary>
            /// <param name="sourceSiteURL"></param>
            protected void ExportSite(string sourceSiteURL, ArrayList arrMoveSite)
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(sourceSiteURL))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                SPExportObject exportObject = new SPExportObject();
                                exportObject.Type = SPDeploymentObjectType.Web;
                                exportObject.Id = web.ID;
                                exportObject.IncludeDescendants = SPIncludeDescendants.All;
    
    
                                SPExportSettings settings = new SPExportSettings();
                                settings.OverwriteExistingDataFile = true;
                                settings.SiteUrl = sourceSiteURL;
                                settings.BaseFileName = EXPORT_FILENAME;
                                settings.ExportMethod = SPExportMethodType.ExportAll;
                                settings.FileLocation = exportFolderName;
                                settings.FileCompression = true;
                                settings.IncludeSecurity = SPIncludeSecurity.All;
                                settings.IncludeVersions = SPIncludeVersions.All;
                                settings.LogFilePath = exportFolderName + web.ID + ".log";
                                settings.ExcludeDependencies = true;
                                settings.ExportObjects.Add(exportObject);
    
                                SPExport export = new SPExport(settings);
                                export.Run();
                                //Display Result
                                arrMoveSite.Add("Site "+web.Url.Substring(web.Url.LastIndexOf("/") + 1) + " has been exported successfully!");
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    Log(ex, ex.Message);
                }
            }
    
            /// <summary>
            /// Imports plant site.
            /// </summary>
            /// <param name="destSiteURL"></param>
            protected void ImportSite(string destSiteURL)
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite rootSiteColl = new SPSite(destSiteURL))
                        {
                            rootSiteColl.AllowUnsafeUpdates = true;
                            using (SPWeb rootWeb = rootSiteColl.OpenWeb())
                            {
                                rootWeb.AllowUnsafeUpdates = true;
                                SPUtility.ValidateFormDigest();
                                SPImportSettings importSettings = new SPImportSettings();
                                importSettings.SiteUrl = rootWeb.Url;
                                importSettings.WebUrl = rootWeb.Url;
                                importSettings.FileLocation = exportFolderName;
                                importSettings.FileCompression = true;
                                importSettings.BaseFileName = EXPORT_FILENAME;
                                importSettings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
                                importSettings.IncludeSecurity = SPIncludeSecurity.All;
                                importSettings.UpdateVersions = SPUpdateVersions.Append;
                                importSettings.LogFilePath = exportFolderName + rootWeb.ID + ".log";
                                //importSettings.RetainObjectIdentity = false;
                                importSettings.Validate();
                                SPImport import = new SPImport(importSettings);
                                import.Run();
    
                                rootWeb.AllowUnsafeUpdates = false;
                                rootWeb.Close();
                            }
                            rootSiteColl.AllowUnsafeUpdates = false;
    
                        }
                    });
                }
                catch (Exception ex)
                {
                    Log(ex, ex.Message);
                }
  • 相关阅读:
    CoreData
    转场动画
    java基础(8)
    java基础(7)
    java基础(6)
    java基础(5)
    java基础(4)
    java基础(3)
    java基础(2)
    java基础(1)
  • 原文地址:https://www.cnblogs.com/ahghy/p/2879644.html
Copyright © 2011-2022 走看看