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);
                }
  • 相关阅读:
    [转]只有tcp6没有tcp问题
    Makefile 中:= ?= += =的区别
    【转】docker images 介绍
    [转]我眼中的 Docker(二)Image
    【转】一个简单的Dockerfile实例
    【转】Prometheus 介绍
    [转]MySQL索引类型按存储类型和逻辑区分
    【转】mysql索引类型
    用Unity制作游戏,你需要深入了解一下IL2CPP
    c++中CreateEvent函数
  • 原文地址:https://www.cnblogs.com/ahghy/p/2879644.html
Copyright © 2011-2022 走看看