/// <summary> /// 既存サイトの定義をテンプレートとして取得 /// </summary> /// <param name="siteConnectionInfo">SharePointサイト接続情報</param> /// <param name="templateSaveInfo">テンプレート保管場所情報</param> /// <param name="progress">進捗報告オブジェクト</param> /// <returns>サイト定義(XML)</returns> public static async Task <string> SaveSiteAsProvisioningTemplateAsync(SiteConnectionInfo siteConnectionInfo, IConnectionInfo templateSaveInfo, IProgress <string> progress = null) { // 戻り値 string ret; progress?.Report("テンプレート取得開始"); using (var ctx = new ClientContext(siteConnectionInfo.WebAbsoluteUrl)) { #region SharePointサイトに接続 progress?.Report($"1/3 SharePointサイトに接続"); ctx.Credentials = new SharePointOnlineCredentials(siteConnectionInfo.UserAccount, siteConnectionInfo.UserSecurePassword); ctx.RequestTimeout = Timeout.Infinite; var web = ctx.Web; ctx.Load(web, w => w.Title); await ctx.ExecuteQueryRetryAsync().ConfigureAwait(false); #endregion #region テンプレートを取得 // テンプレート取得オプション var creationInfo = new ProvisioningTemplateCreationInformation(ctx.Web) { // 進捗報告 ProgressDelegate = delegate(String pnpMessage, Int32 pnpProgress, Int32 pnpTotal) { progress?.Report($"2/3 テンプレートを取得 - {pnpProgress}/{pnpTotal} {pnpMessage}"); }, // ロゴ等のファイル依存ファイル出力先 FileConnector = templateSaveInfo.GetConnector(persistFilesPath), // ブランディング用ファイルを含める(テーマ/ロゴ/代替CSSなど) PersistBrandingFiles = true, // マスターページ/ページレイアウトを含む IncludeNativePublishingFiles = true, // 検索設定を含む IncludeSearchConfiguration = true, // 用語ストアを含む IncludeSiteCollectionTermGroup = true, // SharePointグループを含む IncludeSiteGroups = true, // 用語セットを含める IncludeAllTermGroups = true, // 用語セットの権限を含める IncludeTermGroupsSecurity = true, // 隠しリストを含める IncludeHiddenLists = true, // 「ページ」ライブラリ内の全ページを含める IncludeAllClientSidePages = true, // 発行ファイル(マスターページ/ページレイアウトなど)を含む PersistPublishingFiles = true }; // テンプレート取得 var template = ctx.Web.GetProvisioningTemplate(creationInfo); progress?.Report($"2/3 テンプレートを取得 - 完了"); ret = template.ToXML(); // テンプレート保存 progress?.Report($"3/3 テンプレートを保存:{ templateSaveInfo.FileIdentifer }"); templateSaveInfo.GetConnector().SaveFileStream(templateSaveInfo.FileIdentifer, new MemoryStream(Encoding.UTF8.GetBytes(ret))); #endregion } progress?.Report("テンプレート取得終了"); // 返却 return(ret); }