本文整理汇总了C#中Web.IsSubSite方法的典型用法代码示例。如果您正苦于以下问题:C# Web.IsSubSite方法的具体用法?C# Web.IsSubSite怎么用?C# Web.IsSubSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.IsSubSite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
// if this is a sub site then we're not provisioning fields. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
return;
}
var parser = new TokenParser(web);
var existingFields = web.Fields;
web.Context.Load(existingFields, fs => fs.Include(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingFieldIds = existingFields.Select(l => l.Id).ToList();
var fields = template.SiteFields;
foreach (var field in fields)
{
XDocument document = XDocument.Parse(field.SchemaXml);
var fieldId = document.Root.Attribute("ID").Value;
if (!existingFieldIds.Contains(Guid.Parse(fieldId)))
{
var fieldXml = parser.Parse(field.SchemaXml);
web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.DefaultValue);
web.Context.ExecuteQueryRetry();
}
}
}
示例2: CreateEntities
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
// if this is a sub site then we're not creating content type entities.
if (web.IsSubSite())
{
return template;
}
var cts = web.ContentTypes;
web.Context.Load(cts);
web.Context.ExecuteQuery();
foreach (var ct in cts)
{
if (!BuiltInContentTypeId.Contains(ct.StringId))
{
template.ContentTypes.Add(new Birchman.RemoteProvisioning.Domain.Model.ContentType() { SchemaXml = ct.SchemaXml });
}
}
// If a base template is specified then use that one to "cleanup" the generated template model
if (creationInfo.BaseTemplate != null)
{
template = CleanupEntities(template, creationInfo.BaseTemplate);
}
return template;
}
示例3: CreateEntities
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
// if this is a sub site then we're not creating field entities.
if (web.IsSubSite())
{
return template;
}
var existingFields = web.Fields;
web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml));
web.Context.ExecuteQueryRetry();
foreach (var field in existingFields)
{
if (!BuiltInFieldId.Contains(field.Id))
{
template.SiteFields.Add(new Field() { SchemaXml = field.SchemaXml });
}
}
// If a base template is specified then use that one to "cleanup" the generated template model
if (creationInfo.BaseTemplate != null)
{
template = CleanupEntities(template, creationInfo.BaseTemplate);
}
return template;
}
示例4: CreateEntities
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
// if this is a sub site then we're not creating security entities as by default security is inherited from the root site
if (web.IsSubSite())
{
return template;
}
var ownerGroup = web.AssociatedOwnerGroup;
var memberGroup = web.AssociatedMemberGroup;
var visitorGroup = web.AssociatedVisitorGroup;
web.Context.Load(ownerGroup, o => o.Users);
web.Context.Load(memberGroup, o => o.Users);
web.Context.Load(visitorGroup, o => o.Users);
web.Context.ExecuteQueryRetry();
var owners = ownerGroup.IsObjectPropertyInstantiated("Users") ?
ownerGroup.Users.AsEnumerable().Select(u => new User(){ Name = u.LoginName}).ToList() :
new List<User>();
var members = memberGroup.IsObjectPropertyInstantiated("Users") ?
memberGroup.Users.AsEnumerable().Select(u => new User() { Name = u.LoginName }).ToList() :
new List<User>();
var visitors = visitorGroup.IsObjectPropertyInstantiated("Users") ?
visitorGroup.Users.AsEnumerable().Select(u => new User() { Name = u.LoginName }).ToList() :
new List<User>();
var siteSecurity = new SiteSecurity();
siteSecurity.AdditionalOwners.AddRange(owners);
siteSecurity.AdditionalMembers.AddRange(members);
siteSecurity.AdditionalVisitors.AddRange(visitors);
var allUsers = web.SiteUsers;
web.Context.Load(allUsers, users => users.Include(u => u.LoginName, u => u.IsSiteAdmin));
web.Context.ExecuteQueryRetry();
var admins = new List<User>();
foreach (var member in allUsers)
{
if (member.IsSiteAdmin)
{
admins.Add(new User() {Name = member.LoginName});
}
}
siteSecurity.AdditionalAdministrators.AddRange(admins);
template.Security = siteSecurity;
// If a base template is specified then use that one to "cleanup" the generated template model
if (creationInfo.BaseTemplate != null)
{
template = CleanupEntities(template, creationInfo.BaseTemplate);
}
return template;
}
示例5: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_Fields);
// if this is a sub site then we're not provisioning fields. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
return;
}
var existingFields = web.Fields;
web.Context.Load(existingFields, fs => fs.Include(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingFieldIds = existingFields.AsEnumerable<SPField>().Select(l => l.Id).ToList();
var fields = template.SiteFields;
foreach (var field in fields)
{
XElement templateFieldElement = XElement.Parse(field.SchemaXml.ToParsedString("~sitecollection", "~site"));
var fieldId = templateFieldElement.Attribute("ID").Value;
if (!existingFieldIds.Contains(Guid.Parse(fieldId)))
{
CreateField(web, templateFieldElement);
}
else
{
UpdateField(web, fieldId, templateFieldElement);
}
}
}
示例6: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
// if this is a sub site then we're not provisioning security as by default security is inherited from the root site
if (web.IsSubSite())
{
return;
}
var siteSecurity = template.Security;
var ownerGroup = web.AssociatedOwnerGroup;
var memberGroup = web.AssociatedMemberGroup;
var visitorGroup = web.AssociatedVisitorGroup;
web.Context.Load(ownerGroup, o => o.Users);
web.Context.Load(memberGroup, o => o.Users);
web.Context.Load(visitorGroup, o => o.Users);
web.Context.ExecuteQueryRetry();
AddUserToGroup(web, ownerGroup, siteSecurity.AdditionalOwners);
AddUserToGroup(web, memberGroup, siteSecurity.AdditionalMembers);
AddUserToGroup(web, visitorGroup, siteSecurity.AdditionalVisitors);
foreach (var admin in siteSecurity.AdditionalAdministrators)
{
var user = web.EnsureUser(admin.Name);
user.IsSiteAdmin = true;
user.Update();
web.Context.ExecuteQueryRetry();
}
}
示例7: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
var site = context.Site;
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
// if this is a sub site then we're not enabling the site collection scoped custom actions
if (!web.IsSubSite())
{
var siteCustomActions = template.CustomActions.SiteCustomActions;
ProvisionCustomActionImplementation(site, siteCustomActions, parser, scope, isNoScriptSite);
}
var webCustomActions = template.CustomActions.WebCustomActions;
ProvisionCustomActionImplementation(web, webCustomActions, parser, scope, isNoScriptSite);
// Switch parser context back to it's original context
parser.Rebase(web);
}
return parser;
}
示例8: CreateEntities
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
var context = web.Context as ClientContext;
bool isSubSite = web.IsSubSite();
var webCustomActions = web.GetCustomActions();
var siteCustomActions = context.Site.GetCustomActions();
var customActions = new CustomActions();
foreach (var customAction in webCustomActions)
{
customActions.WebCustomActions.Add(CopyUserCustomAction(customAction));
}
// if this is a sub site then we're not creating entities for site collection scoped custom actions
if (!isSubSite)
{
foreach (var customAction in siteCustomActions)
{
customActions.SiteCustomActions.Add(CopyUserCustomAction(customAction));
}
}
template.CustomActions = customActions;
// If a base template is specified then use that one to "cleanup" the generated template model
if (creationInfo.BaseTemplate != null)
{
template = CleanupEntities(template, creationInfo.BaseTemplate, isSubSite);
}
return template;
}
示例9: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
// if this is a sub site then we're not provisioning content types. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
return;
}
var existingCts = web.AvailableContentTypes;
web.Context.Load(existingCts, cts => cts.Include(ct => ct.StringId));
web.Context.ExecuteQuery();
//TODO: Upgrade to SharePoint.Client v16.0 so refactoring can be done (uncomment following line when done!)
//var existingCtsIds = existingCts.Select(cts => cts.StringId.ToLower()).ToList();
var existingCtsIds = existingCts.AsEnumerable().Select(cts => cts.StringId.ToLower()).ToList();
foreach (var ct in template.ContentTypes)
{
// find the id of the content type
XDocument document = XDocument.Parse(ct.SchemaXml);
var contentTypeId = document.Root.Attribute("ID").Value;
if (!existingCtsIds.Contains(contentTypeId.ToLower()))
{
web.CreateContentTypeFromXMLString(ct.SchemaXml);
existingCtsIds.Add(contentTypeId);
}
}
}
示例10: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// if this is a sub site then we're not provisioning content types. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Context_web_is_subweb__Skipping_content_types_);
return parser;
}
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
web.Context.Load(web.ContentTypes, ct => ct.IncludeWithDefaultProperties(c => c.StringId, c => c.FieldLinks,
c => c.FieldLinks.Include(fl => fl.Id, fl => fl.Required, fl => fl.Hidden)));
web.Context.Load(web.Fields, fld => fld.IncludeWithDefaultProperties(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingCTs = web.ContentTypes.ToList();
var existingFields = web.Fields.ToList();
foreach (var ct in template.ContentTypes.OrderBy(ct => ct.Id)) // ordering to handle references to parent content types that can be in the same template
{
var existingCT = existingCTs.FirstOrDefault(c => c.StringId.Equals(ct.Id, StringComparison.OrdinalIgnoreCase));
if (existingCT == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Creating_new_Content_Type___0_____1_, ct.Id, ct.Name);
var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
if (ct.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Recreating_existing_Content_Type___0_____1_, ct.Id, ct.Name);
existingCT.DeleteObject();
web.Context.ExecuteQueryRetry();
var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Updating_existing_Content_Type___0_____1_, ct.Id, ct.Name);
UpdateContentType(web, existingCT, ct, parser, scope, isNoScriptSite);
}
}
}
}
return parser;
}
示例11: CreateEntities
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
// if this is a sub site then we're not creating field entities.
if (web.IsSubSite())
{
return template;
}
var existingFields = web.Fields;
web.Context.Load(web, w => w.ServerRelativeUrl);
web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml));
web.Context.ExecuteQueryRetry();
foreach (var field in existingFields)
{
if (!BuiltInFieldId.Contains(field.Id))
{
var fieldXml = field.SchemaXml;
XElement element = XElement.Parse(fieldXml);
// Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths
var listIdentifier = element.Attribute("List") != null ? element.Attribute("List").Value : null;
if (!string.IsNullOrEmpty(listIdentifier))
{
var listGuid = Guid.Empty;
if (Guid.TryParse(listIdentifier, out listGuid))
{
var list = web.Lists.GetById(listGuid);
web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl);
web.Context.ExecuteQueryRetry();
var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/');
element.Attribute("List").SetValue(listUrl);
fieldXml = element.ToString();
}
}
// Check if we have version attribute. Remove if exists
if (element.Attribute("Version") != null)
{
element.Attributes("Version").Remove();
fieldXml = element.ToString();
}
template.SiteFields.Add(new Field() { SchemaXml = fieldXml });
}
}
// If a base template is specified then use that one to "cleanup" the generated template model
if (creationInfo.BaseTemplate != null)
{
template = CleanupEntities(template, creationInfo.BaseTemplate);
}
return template;
}
示例12: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// if this is a sub site then we're not provisioning fields. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns);
return parser;
}
var existingFields = web.Fields;
web.Context.Load(existingFields, fs => fs.Include(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingFieldIds = existingFields.AsEnumerable<SPField>().Select(l => l.Id).ToList();
var fields = template.SiteFields;
foreach (var field in fields)
{
XElement templateFieldElement = XElement.Parse(parser.ParseString(field.SchemaXml, "~sitecollection", "~site"));
var fieldId = templateFieldElement.Attribute("ID").Value;
if (!existingFieldIds.Contains(Guid.Parse(fieldId)))
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Adding_field__0__to_site, fieldId);
CreateField(web, templateFieldElement, scope, parser, field.SchemaXml);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Fields_Adding_field__0__failed___1_____2_, fieldId, ex.Message, ex.StackTrace);
throw;
}
}
else
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Updating_field__0__in_site, fieldId);
UpdateField(web, fieldId, templateFieldElement, scope, parser, field.SchemaXml);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Fields_Updating_field__0__failed___1_____2_, fieldId, ex.Message, ex.StackTrace);
throw;
}
}
}
return parser;
}
示例13: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
var context = web.Context as ClientContext;
// if this is a sub site then we're not enabling the site collection scoped features
if (!web.IsSubSite())
{
var siteFeatures = template.Features.SiteFeatures;
ProvisionFeaturesImplementation(context.Site, siteFeatures);
}
var webFeatures = template.Features.WebFeatures;
ProvisionFeaturesImplementation(web, webFeatures);
}
示例14: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
var context = web.Context as ClientContext;
var site = context.Site;
// if this is a sub site then we're not enabling the site collection scoped custom actions
if (!web.IsSubSite())
{
var siteCustomActions = template.CustomActions.SiteCustomActions;
ProvisionCustomActionImplementation(site, siteCustomActions);
}
var webCustomActions = template.CustomActions.WebCustomActions;
ProvisionCustomActionImplementation(web, webCustomActions);
}
示例15: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_ContentTypes);
// if this is a sub site then we're not provisioning content types. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
return;
}
web.Context.Load(web.ContentTypes, ct => ct.IncludeWithDefaultProperties(c => c.StringId, c => c.FieldLinks));
web.Context.ExecuteQueryRetry();
var existingCTs = web.ContentTypes.ToList();
foreach (var ct in template.ContentTypes.OrderBy(ct => ct.Id)) // ordering to handle references to parent content types that can be in the same template
{
var existingCT = existingCTs.FirstOrDefault(c => c.StringId.Equals(ct.Id, StringComparison.OrdinalIgnoreCase));
if (existingCT == null)
{
var newCT = CreateContentType(web, ct);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
if (ct.Overwrite)
{
existingCT.DeleteObject();
web.Context.ExecuteQueryRetry();
var newCT = CreateContentType(web, ct);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
UpdateContentType(web, existingCT, ct);
}
}
}
}