I'm creating my ContentTypes and after that I'm trying to create my fields.
I'm curently hitting my head on the wall, after searching for a few hours about how to get the Groups, that you can place fields in(check Picture to see what I'm refering to)
Can someone explain how am i able to get a list of those Groups from my Picture?
var web = _Ctx.Web;
_Ctx.Load(web, w => w.ContentTypes, w => w.Fields);
_Ctx.ExecuteQuery();
foreach (lavaPOINT_Page page in new PageAndFieldData().Pages)
{
if (!web.ContentTypes.ToList().Exists(i => i.Id.ToString() == page.ID))
{
var spbt = web.ContentTypes.Add(new ContentTypeCreationInformation()
{
Name = page.Name,
Id = page.ID,
Group = page.Group,
Description = page.Group
});
_Ctx.Load(spbt, f => f, f => f.Fields.Include(i => i.InternalName));
_Ctx.ExecuteQuery();
}
}
var fields = web.Fields;
var Groups = ? // how do i get the Groups *??
foreach (var field in new PageAndFieldData().Fields)
{
var teaser = web.Fields.FirstOrDefault(i => i.InternalName == field.field_name); // if dont exist = create
if (teaser == null)
{
var fieldXml = "<Field Type=\"Note\" DisplayName=\"Teaser\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" NumLines=\"6\" RichText=\"FALSE\" Sortable=\"FALSE\" Group=\"Fields\" ID=\"{fdfba8f7-4521-4db4-b6c2-8ab88e065834}\" SourceID=\"{5119e221-4abe-4200-8d82-910db701336a}\" StaticName=\"NewsPageTeaser\" Name=\"NewsPageTeaser\" RestrictedMode=\"TRUE\" RichTextMode=\"Compatible\" IsolateStyles=\"FALSE\" AppendOnly=\"FALSE\" UnlimitedLengthInDocumentLibrary=\"FALSE\"></Field>";
var spField = web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.DefaultValue);
//_Ctx.Load(spField);
//_Ctx.ExecuteQuery();
}
}
I found a way to get all the Groups. But kinda sure it aint the best.
var groups = fields.ToList().Select(i => i.Group).Distinct();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.