protected override void ProcessRecord() { base.ProcessRecord(); var ctx = base.Context; Web web = ctx.Site.OpenWeb(Web.Read()); SPOContentType contentType = null; if (List == null) { contentType = ContentType.Read(web); } else { SPOList list = List.Read(web, false); contentType = ContentType.Read(list.List); } if (contentType == null) { throw new ArgumentException("Unable to locate the specified content type."); } if (base.ShouldProcess(contentType.Name, "Remove Content Type")) { contentType.Delete(); } }
protected override void ProcessRecord() { base.ProcessRecord(); var ctx = base.Context; Web web = ctx.Site.OpenWeb(Web.Read()); SPOContentType newContentType = null; SPOList list = List.Read(web, false); SPOContentType parentContentType = ContentType.Read(web); if (parentContentType == null) { throw new ArgumentException("Unable to locate the specified parent content type."); } SPOContentType existingContentType = SPOContentType.GetContentType(ctx, list.List.ContentTypes, parentContentType.Name); if (existingContentType != null) { WriteWarning("The content type \"" + parentContentType.Name + "\" already exists within the List."); WriteObject(existingContentType); return; } ContentType ct = list.List.ContentTypes.AddExistingContentType(parentContentType.ContentType); ctx.ExecuteQuery(); SPOContentType.LoadContentType(ctx, ct); newContentType = new SPOContentType(ct); WriteObject(newContentType); }
public void Refresh() { _item.RefreshLoad(); _item.Context.ExecuteQuery(); _ct = null; }
protected override void ProcessRecord() { base.ProcessRecord(); var ctx = base.Context; string surl = Web.Read(); Web web = ctx.Site.OpenWeb(surl); ContentTypeCollection contentTypes = null; if (ParameterSetName == "Web") { contentTypes = web.ContentTypes; } else if (ParameterSetName == "List") { SPOList list = List.Read(web, false); contentTypes = list.List.ContentTypes; } ctx.Load(contentTypes); ctx.ExecuteQuery(); foreach (ContentType ct in contentTypes) { if (string.IsNullOrEmpty(Identity) || ct.Name.ToLower() == Identity.ToLower() || ct.Id.StringValue.ToLower() == Identity.ToLower()) { SPOContentType.LoadContentType(ctx, ct); WriteObject(new SPOContentType(ct)); } } }
public SPOContentType GetContentType() { if (_ct != null) { return(_ct); } SPOContentType.LoadContentType(SPOSiteContext.CurrentSiteContext.Context, _item.ContentType); _ct = new SPOContentType(_item.ContentType); return(_ct); }
public SPOContentTypePipeBind(ContentType contentType) { if ((contentType == null)) { throw new ArgumentNullException("The Content Type must be specified."); } _spoContentType = new SPOContentType(contentType); _contentType = contentType; _name = contentType.Name; _contentTypeId = contentType.Id.StringValue; }
public List <SPOContentType> GetAvailableContentTypes() { if (_availableContentTypes != null) { return(_availableContentTypes); } var ctx = SPOSiteContext.CurrentSiteContext.Context; var contentTypes = Web.AvailableContentTypes; ctx.Load(contentTypes); ctx.ExecuteQuery(); _availableContentTypes = new List <SPOContentType>(); foreach (ContentType contentType in contentTypes) { SPOContentType.LoadContentType(ctx, contentType); _availableContentTypes.Add(new SPOContentType(contentType)); } return(_availableContentTypes); }
private SPOContentType Read(ContentTypeCollection contentTypes) { var ctx = SPOSiteContext.CurrentSiteContext.Context; ContentType contentType = null; if (_contentTypeId != null) { contentType = contentTypes.GetById(_contentTypeId); } else if (!string.IsNullOrEmpty(_name)) { ctx.Load(contentTypes); ctx.ExecuteQuery(); foreach (ContentType ct in contentTypes) { if (ct.Name.ToLower() == _name.ToLower()) { contentType = ct; break; } } } if (contentType != null) { SPOContentType.LoadContentType(ctx, contentType); if (contentType.ServerObjectIsNull.Value) { return(null); } return(new SPOContentType(contentType)); } return(null); }
protected override void ProcessRecord() { base.ProcessRecord(); var ctx = base.Context; Web web = ctx.Site.OpenWeb(Web.Read()); SPOContentType newContentType = null; SPOContentType parentContentType = ParentContentType.Read(web); if (parentContentType == null) { throw new ArgumentException("Unable to locate the specified parent content type."); } SPOContentType existingContentType = SPOContentType.GetContentType(ctx, web.AvailableContentTypes, Name); if (existingContentType != null) { WriteWarning("The content type \"" + Name + "\" already exists within the Site."); WriteObject(existingContentType); return; } List <SPOField> fields = new List <SPOField>(); if (FieldsToAdd != null) { foreach (string fieldName in FieldsToAdd) { SPOField existingField = SPOField.GetField(ctx, web.AvailableFields, fieldName); if (existingField == null) { WriteError(new ErrorRecord(new ArgumentOutOfRangeException("Unable to locate field " + fieldName + ". Content Type will not be created."), null, ErrorCategory.InvalidData, web.AvailableFields)); } else { fields.Add(existingField); } } if (fields.Count != FieldsToAdd.Length) { return; } } var ctli = new ContentTypeCreationInformation(); ctli.Description = Description; ctli.Group = Group; ctli.Name = Name; ctli.ParentContentType = parentContentType.ContentType; ContentType ct = web.ContentTypes.Add(ctli); ctx.ExecuteQuery(); SPOContentType.LoadContentType(ctx, ct); newContentType = new SPOContentType(ct); foreach (SPOField field in fields) { FieldLinkCreationInformation flci = new FieldLinkCreationInformation(); flci.Field = field.Field; newContentType.ContentType.FieldLinks.Add(flci); } if (fields.Count > 0) { newContentType.ContentType.Update(true); ctx.ExecuteQuery(); } WriteObject(newContentType); }
public SPOContentTypePipeBind(SPOContentType contentType) { this._contentType = contentType.ContextObject; }
protected override void ExecuteCmdlet() { SPOContentType ct = new SPOContentType(this.SelectedWeb.CreateContentType(Name, Description, ContentTypeId, Group, ParentContentType)); WriteObject(ct); }