本文整理汇总了C#中Web.AddFieldToContentType方法的典型用法代码示例。如果您正苦于以下问题:C# Web.AddFieldToContentType方法的具体用法?C# Web.AddFieldToContentType怎么用?C# Web.AddFieldToContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.AddFieldToContentType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType ct)
{
var name = ct.Name.ToParsedString();
var description = ct.Description.ToParsedString();
var id = ct.Id.ToParsedString();
var group = ct.Group.ToParsedString();
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in ct.FieldRefs)
{
var field = web.Fields.GetById(fieldRef.Id);
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
createdCT.ReadOnly = ct.ReadOnly;
createdCT.Hidden = ct.Hidden;
createdCT.Sealed = ct.Sealed;
if (!string.IsNullOrEmpty(ct.DocumentTemplate))
{
createdCT.DocumentTemplate = ct.DocumentTemplate;
}
web.Context.Load(createdCT);
web.Context.ExecuteQueryRetry();
return createdCT;
}
示例2: UpdateContentType
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope)
{
var isDirty = false;
if (existingContentType.Hidden != templateContentType.Hidden)
{
scope.LogPropertyUpdate("Hidden");
existingContentType.Hidden = templateContentType.Hidden;
isDirty = true;
}
if (existingContentType.ReadOnly != templateContentType.ReadOnly)
{
scope.LogPropertyUpdate("ReadOnly");
existingContentType.ReadOnly = templateContentType.ReadOnly;
isDirty = true;
}
if (existingContentType.Sealed != templateContentType.Sealed)
{
scope.LogPropertyUpdate("Sealed");
existingContentType.Sealed = templateContentType.Sealed;
isDirty = true;
}
if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description))
{
scope.LogPropertyUpdate("Description");
existingContentType.Description = parser.ParseString(templateContentType.Description);
isDirty = true;
}
if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate))
{
scope.LogPropertyUpdate("DocumentTemplate");
existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
isDirty = true;
}
if (existingContentType.Name != parser.ParseString(templateContentType.Name))
{
scope.LogPropertyUpdate("Name");
existingContentType.Name = parser.ParseString(templateContentType.Name);
isDirty = true;
}
if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group))
{
scope.LogPropertyUpdate("Group");
existingContentType.Group = parser.ParseString(templateContentType.Group);
isDirty = true;
}
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
// Delta handling
List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList();
List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList();
var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray();
if (fieldsNotPresentInTarget.Any())
{
foreach (var fieldId in fieldsNotPresentInTarget)
{
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
var field = web.Fields.GetById(fieldId);
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, field.Id);
web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden);
}
}
isDirty = false;
foreach (var fieldId in targetIds.Intersect(sourceIds))
{
var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId);
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
if (fieldRef != null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Field__0__exists_in_content_type, fieldId);
if (fieldLink.Required != fieldRef.Required)
{
scope.LogPropertyUpdate("Required");
fieldLink.Required = fieldRef.Required;
isDirty = true;
}
if (fieldLink.Hidden != fieldRef.Hidden)
{
scope.LogPropertyUpdate("Hidden");
fieldLink.Hidden = fieldRef.Hidden;
isDirty = true;
}
}
}
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
}
示例3: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
var field = web.Fields.GetById(fieldRef.Id);
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
web.Context.Load(createdCT);
web.Context.ExecuteQueryRetry();
return createdCT;
}
示例4: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
var field = web.Fields.GetById(fieldRef.Id);
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
if (!String.IsNullOrEmpty(templateContentType.NewFormUrl))
{
createdCT.NewFormUrl = templateContentType.NewFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.EditFormUrl))
{
createdCT.EditFormUrl = templateContentType.EditFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.DisplayFormUrl))
{
createdCT.DisplayFormUrl = templateContentType.DisplayFormUrl;
}
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate documentSetTemplate =
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, createdCT);
if (!String.IsNullOrEmpty(templateContentType.DocumentSetTemplate.WelcomePage))
{
// TODO: Customize the WelcomePage of the DocumentSet
}
foreach (String ctId in templateContentType.DocumentSetTemplate.AllowedContentTypes)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == ctId);
if (ct != null)
{
documentSetTemplate.AllowedContentTypes.Add(ct.Id);
}
}
foreach (var doc in templateContentType.DocumentSetTemplate.DefaultDocuments)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == doc.ContentTypeId);
if (ct != null)
{
using (Stream fileStream = connector.GetFileStream(doc.FileSourcePath))
{
documentSetTemplate.DefaultDocuments.Add(doc.Name, ct.Id, ReadFullStream(fileStream));
}
}
}
foreach (var sharedField in templateContentType.DocumentSetTemplate.SharedFields)
{
Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == sharedField);
if (field != null)
{
documentSetTemplate.SharedFields.Add(field);
}
}
foreach (var welcomePageField in templateContentType.DocumentSetTemplate.WelcomePageFields)
{
Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == welcomePageField);
if (field != null)
{
documentSetTemplate.WelcomePageFields.Add(field);
}
}
documentSetTemplate.Update(true);
web.Context.ExecuteQueryRetry();
}
web.Context.Load(createdCT);
web.Context.ExecuteQueryRetry();
return createdCT;
}
示例5: UpdateContentType
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope)
{
var isDirty = false;
if (existingContentType.Hidden != templateContentType.Hidden)
{
scope.LogPropertyUpdate("Hidden");
existingContentType.Hidden = templateContentType.Hidden;
isDirty = true;
}
if (existingContentType.ReadOnly != templateContentType.ReadOnly)
{
scope.LogPropertyUpdate("ReadOnly");
existingContentType.ReadOnly = templateContentType.ReadOnly;
isDirty = true;
}
if (existingContentType.Sealed != templateContentType.Sealed)
{
scope.LogPropertyUpdate("Sealed");
existingContentType.Sealed = templateContentType.Sealed;
isDirty = true;
}
if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description))
{
scope.LogPropertyUpdate("Description");
existingContentType.Description = parser.ParseString(templateContentType.Description);
isDirty = true;
}
if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate))
{
scope.LogPropertyUpdate("DocumentTemplate");
existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
isDirty = true;
}
if (existingContentType.Name != parser.ParseString(templateContentType.Name))
{
scope.LogPropertyUpdate("Name");
existingContentType.Name = parser.ParseString(templateContentType.Name);
isDirty = true;
// CT is being renamed, add an extra token to the tokenparser
parser.AddToken(new ContentTypeIdToken(web, existingContentType.Name, existingContentType.StringId));
}
if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group))
{
scope.LogPropertyUpdate("Group");
existingContentType.Group = parser.ParseString(templateContentType.Group);
isDirty = true;
}
if (templateContentType.DisplayFormUrl != null && existingContentType.DisplayFormUrl != parser.ParseString(templateContentType.DisplayFormUrl))
{
scope.LogPropertyUpdate("DisplayFormUrl");
existingContentType.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
isDirty = true;
}
if (templateContentType.EditFormUrl != null && existingContentType.EditFormUrl != parser.ParseString(templateContentType.EditFormUrl))
{
scope.LogPropertyUpdate("EditFormUrl");
existingContentType.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
isDirty = true;
}
if (templateContentType.NewFormUrl != null && existingContentType.NewFormUrl != parser.ParseString(templateContentType.NewFormUrl))
{
scope.LogPropertyUpdate("NewFormUrl");
existingContentType.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
isDirty = true;
}
#if !CLIENTSDKV15
if (templateContentType.Name.ContainsResourceToken())
{
existingContentType.NameResource.SetUserResourceValue(templateContentType.Name, parser);
isDirty = true;
}
if (templateContentType.Description.ContainsResourceToken())
{
existingContentType.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
isDirty = true;
}
#endif
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
// Delta handling
existingContentType.EnsureProperty(c => c.FieldLinks);
List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList();
List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList();
var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray();
if (fieldsNotPresentInTarget.Any())
{
foreach (var fieldId in fieldsNotPresentInTarget)
{
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
var field = web.Fields.GetById(fieldId);
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, fieldId);
web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden);
}
}
//.........这里部分代码省略.........
示例6: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
var field = web.Fields.GetById(fieldRef.Id);
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
// Add new CTs
parser.AddToken(new ContentTypeIdToken(web, name, id));
#if !CLIENTSDKV15
// Set resources
if (templateContentType.Name.ContainsResourceToken())
{
createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser);
}
if(templateContentType.Description.ContainsResourceToken())
{
createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
}
#endif
//Reorder the elements so that the new created Content Type has the same order as defined in the
//template. The order can be different if the new Content Type inherits from another Content Type.
//In this case the new Content Type has all field of the original Content Type and missing fields
//will be added at the end. To fix this issue we ordering the fields once more.
createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => fld.Name).ToArray());
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
if (!String.IsNullOrEmpty(templateContentType.NewFormUrl))
{
createdCT.NewFormUrl = templateContentType.NewFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.EditFormUrl))
{
createdCT.EditFormUrl = templateContentType.EditFormUrl;
}
if (!String.IsNullOrEmpty(templateContentType.DisplayFormUrl))
{
createdCT.DisplayFormUrl = templateContentType.DisplayFormUrl;
}
createdCT.Update(true);
web.Context.ExecuteQueryRetry();
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate documentSetTemplate =
Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, createdCT);
if (!String.IsNullOrEmpty(templateContentType.DocumentSetTemplate.WelcomePage))
{
// TODO: Customize the WelcomePage of the DocumentSet
}
foreach (String ctId in templateContentType.DocumentSetTemplate.AllowedContentTypes)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == ctId);
if (ct != null)
{
documentSetTemplate.AllowedContentTypes.Add(ct.Id);
}
}
foreach (var doc in templateContentType.DocumentSetTemplate.DefaultDocuments)
{
Microsoft.SharePoint.Client.ContentType ct = existingCTs.FirstOrDefault(c => c.StringId == doc.ContentTypeId);
if (ct != null)
{
using (Stream fileStream = connector.GetFileStream(doc.FileSourcePath))
{
documentSetTemplate.DefaultDocuments.Add(doc.Name, ct.Id, ReadFullStream(fileStream));
}
}
}
foreach (var sharedField in templateContentType.DocumentSetTemplate.SharedFields)
{
Microsoft.SharePoint.Client.Field field = existingFields.FirstOrDefault(f => f.Id == sharedField);
if (field != null)
{
documentSetTemplate.SharedFields.Add(field);
}
}
//.........这里部分代码省略.........
示例7: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector, PnPMonitoredScope scope,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null, bool isNoScriptSite = false)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
Microsoft.SharePoint.Client.Field field = null;
try
{
// Try to get the field by ID
field = web.Fields.GetById(fieldRef.Id);
}
catch (ArgumentException)
{
// In case of failure, if we have the name
if (!String.IsNullOrEmpty(fieldRef.Name))
{
// Let's try with that one
field = web.Fields.GetByInternalNameOrTitle(fieldRef.Name);
}
}
// Add it to the target content type
// Notice that this code will fail if the field does not exist
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
// Add new CTs
parser.AddToken(new ContentTypeIdToken(web, name, id));
#if !ONPREMISES
// Set resources
if (templateContentType.Name.ContainsResourceToken())
{
createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser);
}
if (templateContentType.Description.ContainsResourceToken())
{
createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
}
#endif
//Reorder the elements so that the new created Content Type has the same order as defined in the
//template. The order can be different if the new Content Type inherits from another Content Type.
//In this case the new Content Type has all field of the original Content Type and missing fields
//will be added at the end. To fix this issue we ordering the fields once more.
createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => parser.ParseString(fld.Name)).ToArray());
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (templateContentType.DocumentSetTemplate == null)
{
// Only apply a document template when the contenttype is not a document set
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
}
// Skipping updates of forms as we can't upload forms to noscript sites
if (!isNoScriptSite)
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
createdCT.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)))
{
createdCT.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)))
{
createdCT.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
}
}
else
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
// log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, name);
}
}
createdCT.Update(true);
web.Context.ExecuteQueryRetry();
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
//.........这里部分代码省略.........
示例8: UpdateContentType
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType)
{
var isDirty = false;
if (existingContentType.Hidden != templateContentType.Hidden)
{
existingContentType.Hidden = templateContentType.Hidden;
isDirty = true;
}
if (existingContentType.ReadOnly != templateContentType.ReadOnly)
{
existingContentType.ReadOnly = templateContentType.ReadOnly;
isDirty = true;
}
if (existingContentType.Sealed != templateContentType.Sealed)
{
existingContentType.Sealed = templateContentType.Sealed;
isDirty = true;
}
if (templateContentType.Description != null && existingContentType.Description != templateContentType.Description.ToParsedString())
{
existingContentType.Description = templateContentType.Description.ToParsedString();
isDirty = true;
}
if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != templateContentType.DocumentTemplate.ToParsedString())
{
existingContentType.DocumentTemplate = templateContentType.DocumentTemplate.ToParsedString();
isDirty = true;
}
if (existingContentType.Name != templateContentType.Name.ToParsedString())
{
existingContentType.Name = templateContentType.Name.ToParsedString();
isDirty = true;
}
if (templateContentType.Group != null && existingContentType.Group != templateContentType.Group.ToParsedString())
{
existingContentType.Group = templateContentType.Group.ToParsedString();
isDirty = true;
}
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
// Delta handling
List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList();
List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList();
var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray();
if (fieldsNotPresentInTarget.Any())
{
foreach (var fieldId in fieldsNotPresentInTarget)
{
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
var field = web.Fields.GetById(fieldId);
web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden);
}
}
isDirty = false;
foreach (var fieldId in targetIds.Intersect(sourceIds))
{
var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId);
var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId);
if (fieldRef != null)
{
if (fieldLink.Required != fieldRef.Required)
{
fieldLink.Required = fieldRef.Required;
isDirty = true;
}
if (fieldLink.Hidden != fieldRef.Hidden)
{
fieldLink.Hidden = fieldRef.Hidden;
isDirty = true;
}
}
}
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
}