本文整理汇总了C#中ClientContext.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ClientContext.Clone方法的具体用法?C# ClientContext.Clone怎么用?C# ClientContext.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClientContext
的用法示例。
在下文中一共展示了ClientContext.Clone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpTemplate
private void DumpTemplate(ClientContext ctx, string template, string subSiteTemplate = "", string saveAsTemplate = "")
{
Uri devSiteUrl = new Uri(ConfigurationManager.AppSettings["SPODevSiteUrl"]);
string baseUrl = String.Format("{0}://{1}", devSiteUrl.Scheme, devSiteUrl.DnsSafeHost);
string siteUrl = "";
if (subSiteTemplate.Length > 0)
{
siteUrl = (String.Format("{1}/sites/template{0}/template{2}", template, baseUrl, subSiteTemplate));
}
else
{
siteUrl = (String.Format("{1}/sites/template{0}", template, baseUrl));
}
using (ClientContext cc = ctx.Clone(siteUrl))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
creationInfo.BaseTemplate = null;
// Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
// blankinternet#0 as web template using CSOM/SSOM API
if (saveAsTemplate.Length > 0)
{
template = saveAsTemplate;
}
ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
if (subSiteTemplate.Length > 0)
{
p.Id = String.Format("{0}template", subSiteTemplate);
}
else
{
p.Id = String.Format("{0}template", template);
}
// Cleanup before saving
p.Security.AdditionalAdministrators.Clear();
XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(".", "");
if (subSiteTemplate.Length > 0)
{
provider.SaveAs(p, String.Format("{0}Template.xml", subSiteTemplate));
}
else
{
provider.SaveAs(p, String.Format("{0}Template.xml", template));
}
}
}
示例2: DeployTheme
/// <summary>
/// Update the theme information for the passed site which can be a sub site or root site
/// </summary>
/// <param name="cc">CLient context of the site to operate on</param>
/// <param name="themeName">Theme to apply</param>
private static void DeployTheme(ClientContext cc, string themeName)
{
string themeRoot = Path.Combine(AppRootPath, String.Format(@"Themes\{0}", themeName));
string spColorFile = Path.Combine(themeRoot, string.Format("{0}.spcolor", themeName));
if (!System.IO.File.Exists(spColorFile))
{
spColorFile = null;
}
string spFontFile = Path.Combine(themeRoot, string.Format("{0}.spfont", themeName));
if (!System.IO.File.Exists(spFontFile))
{
spFontFile = null;
}
string spBackgroundFile = Path.Combine(themeRoot, string.Format("{0}bg.jpg", themeName));
if (!System.IO.File.Exists(spBackgroundFile))
{
spBackgroundFile = null;
}
string logoFile = Path.Combine(themeRoot, string.Format("{0}logo.png", themeName));
if (IsThisASubSite(cc))
{
// Retrieve the context of the root site of the site collection
using (ClientContext ccParent = cc.Clone(GetRootSite(cc)))
{
// Show the approach that uses the relative paths to the theme files. Works for sub site composed look setting as well as for root site composed look settings
string colorFileRelativePath = "";
string fontFileRelativePath = "";
string backgroundFileRelativePath = "";
if (!String.IsNullOrEmpty(spColorFile))
{
colorFileRelativePath = ccParent.Web.UploadThemeFile(spColorFile).ServerRelativeUrl;
}
if (!String.IsNullOrEmpty(spFontFile))
{
fontFileRelativePath = ccParent.Web.UploadThemeFile(spFontFile).ServerRelativeUrl;
}
if (!String.IsNullOrEmpty(spBackgroundFile))
{
backgroundFileRelativePath = ccParent.Web.UploadThemeFile(spBackgroundFile).ServerRelativeUrl;
}
cc.Web.CreateComposedLookByUrl(themeName, colorFileRelativePath, fontFileRelativePath, backgroundFileRelativePath, null, replaceContent: true);
cc.Web.SetComposedLookByUrl(themeName);
}
}
else
{
// Use the absolute paths to the theme files, works for the root site only
if (!String.IsNullOrEmpty(spColorFile))
{
cc.Web.UploadThemeFile(spColorFile);
}
if (!String.IsNullOrEmpty(spFontFile))
{
cc.Web.UploadThemeFile(spFontFile);
}
if (!String.IsNullOrEmpty(spBackgroundFile))
{
cc.Web.UploadThemeFile(spBackgroundFile);
}
cc.Web.CreateComposedLookByName(themeName, spColorFile, spFontFile, spBackgroundFile, null, replaceContent: true);
cc.Web.SetComposedLookByUrl(themeName);
}
}
示例3: ApplyCustomTemplateToSite
/// <summary>
/// Applies actual template on top of given site URL.
/// </summary>
/// <param name="webFullUrl"></param>
/// <param name="siteRequest"></param>
public void ApplyCustomTemplateToSite(ClientContext ctx, SiteCollectionRequest siteRequest, string resourcesPath)
{
// Template to be applied to site
ProvisioningTemplate template = null;
// Apply modification to provided site
switch (siteRequest.ProvisioningType)
{
case SiteProvisioningType.Identity:
// Get template from xml file
XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(resourcesPath, "");
template = provider.GetTemplate(siteRequest.TemplateId);
break;
case SiteProvisioningType.TemplateSite:
// Get template from existing site
using (ClientContext cc2 = ctx.Clone(siteRequest.TemplateId))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc2.Web);
creationInfo.BaseTemplate = cc2.Web.GetBaseTemplate();
creationInfo.PersistComposedLookFiles = true;
creationInfo.FileConnector = new FileSystemConnector(resourcesPath, "");
// Get template from existing site
template = cc2.Web.GetProvisioningTemplate(creationInfo);
}
break;
default:
break;
}
// Apply template to the site
template.Connector = new FileSystemConnector(resourcesPath, "");
ctx.Web.ApplyProvisioningTemplate(template);
}
示例4: DumpTemplate
private void DumpTemplate(ClientContext ctx, string template, string subSiteTemplate = "", string saveAsTemplate = "")
{
Uri devSiteUrl = new Uri(ConfigurationManager.AppSettings["SPODevSiteUrl"]);
string baseUrl = String.Format("{0}://{1}", devSiteUrl.Scheme, devSiteUrl.DnsSafeHost);
string siteUrl = "";
if (subSiteTemplate.Length > 0)
{
siteUrl = string.Format("{1}/sites/template{0}/template{2}", template.Replace("#", ""), baseUrl, subSiteTemplate.Replace("#", ""));
#if !CLIENTSDKV15
var siteCollectionUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
CreateSiteCollection(template, siteCollectionUrl);
using (var sitecolCtx = ctx.Clone(siteCollectionUrl))
{
sitecolCtx.Web.Webs.Add(new WebCreationInformation()
{
Title = string.Format("template{0}", subSiteTemplate),
Language = 1033,
Url = string.Format("template{0}", subSiteTemplate.Replace("#", "")),
UseSamePermissionsAsParentSite = true
});
sitecolCtx.ExecuteQueryRetry();
}
#endif
}
else
{
siteUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
#if !CLIENTSDKV15
CreateSiteCollection(template, siteUrl);
#endif
}
using (ClientContext cc = ctx.Clone(siteUrl))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
creationInfo.BaseTemplate = null;
// Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
// blankinternet#0 as web template using CSOM/SSOM API
if (saveAsTemplate.Length > 0)
{
template = saveAsTemplate;
}
ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
if (subSiteTemplate.Length > 0)
{
p.Id = String.Format("{0}template", subSiteTemplate.Replace("#", ""));
}
else
{
p.Id = String.Format("{0}template", template.Replace("#", ""));
}
// Cleanup before saving
p.Security.AdditionalAdministrators.Clear();
XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(".", "");
if (subSiteTemplate.Length > 0)
{
provider.SaveAs(p, String.Format("{0}Template.xml", subSiteTemplate.Replace("#", "")));
}
else
{
provider.SaveAs(p, String.Format("{0}Template.xml", template.Replace("#", "")));
}
#if !CLIENTSDKV15
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
Tenant tenant = new Tenant(tenantCtx);
Console.WriteLine("Deleting new site {0}", string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl));
tenant.DeleteSiteCollection(siteUrl, false);
}
#endif
}
}
示例5: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
var tenant = new Tenant(tenantContext);
try
{
using (ClientContext cc = tenantContext.Clone(devSiteUrl))
{
var sites = cc.Web.SiteSearch();
foreach(var site in sites)
{
if (site.Url.ToLower().Contains(sitecollectionNamePrefix.ToLower()))
{
tenant.DeleteSiteCollection(site.Url);
}
}
}
}
catch
{ }
}