/// <summary> /// Checks if a site column exists in a site and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnDetail">The details of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureSiteColumn(this SPWeb site, ColumnDetails columnDetail, ref bool isNewColumn) { isNewColumn = false; SPField column = null; if (!site.Fields.ContainsField(columnDetail.InternalName)) { site.Fields.AddFieldAsXml(columnDetail.GetXml()); column = site.Fields.GetFieldByInternalName(columnDetail.InternalName); isNewColumn = true; } else { column = site.Fields.GetFieldByInternalName(columnDetail.InternalName); } return column; }
/// <summary> /// Checks if a site column exists in a site and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnDetail">The details of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureSiteColumn(this SPWeb site, ColumnDetails columnDetail, ref bool isNewColumn) { isNewColumn = false; SPField column = null; if (!site.Fields.ContainsField(columnDetail.InternalName)) { site.Fields.AddFieldAsXml(columnDetail.GetXml()); column = site.Fields.GetFieldByInternalName(columnDetail.InternalName); isNewColumn = true; } else { column = site.Fields.GetFieldByInternalName(columnDetail.InternalName); } return(column); }
/// <summary> /// Checks if a column exists in a list and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnDetail">The details of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureColumn(this SPList list, ColumnDetails columnDetail, bool isSiteColumn, ref bool isNewColumn) { isNewColumn = false; SPField column = null; if (!list.Fields.ContainsField(columnDetail.InternalName)) { if (!isSiteColumn) { // When a column is created using AddAsXml in a list (using it in a site isn't affected), set the display name to the internal name to workaround a bug that creates the column using the display name. ColumnDetails tempDetail = new ColumnDetails(columnDetail); if (tempDetail.Id.Equals(Guid.Empty)) { tempDetail.Id = Guid.NewGuid(); } tempDetail.DisplayName = tempDetail.InternalName; string internalName = list.Fields.AddFieldAsXml(tempDetail.GetXml()); column = list.Fields.GetFieldByInternalName(internalName); column.Title = columnDetail.DisplayName; column.Update(); column = list.Fields.GetFieldByInternalName(internalName); //refresh the context } else { SPField siteColumn = list.ParentWeb.AvailableFields.GetFieldByInternalName(columnDetail.InternalName); string internalName = list.Fields.Add(siteColumn); column = list.Fields.GetFieldByInternalName(internalName); } isNewColumn = true; } else { column = list.Fields.GetFieldByInternalName(columnDetail.InternalName); } return(column); }
/// <summary> /// Checks if a column exists in a list and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnDetail">The details of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureColumn(this SPList list, ColumnDetails columnDetail, bool isSiteColumn, ref bool isNewColumn) { isNewColumn = false; SPField column = null; if (!list.Fields.ContainsField(columnDetail.InternalName)) { if (!isSiteColumn) { // When a column is created using AddAsXml in a list (using it in a site isn't affected), set the display name to the internal name to workaround a bug that creates the column using the display name. ColumnDetails tempDetail = new ColumnDetails(columnDetail); if (tempDetail.Id.Equals(Guid.Empty)) { tempDetail.Id = Guid.NewGuid(); } tempDetail.DisplayName = tempDetail.InternalName; string internalName = list.Fields.AddFieldAsXml(tempDetail.GetXml()); column = list.Fields.GetFieldByInternalName(internalName); column.Title = columnDetail.DisplayName; column.Update(); column = list.Fields.GetFieldByInternalName(internalName); //refresh the context } else { SPField siteColumn = list.ParentWeb.AvailableFields.GetFieldByInternalName(columnDetail.InternalName); string internalName = list.Fields.Add(siteColumn); column = list.Fields.GetFieldByInternalName(internalName); } isNewColumn = true; } else { column = list.Fields.GetFieldByInternalName(columnDetail.InternalName); } return column; }
public ColumnDetails(ColumnDetails columnDetail) : this(columnDetail.Id, columnDetail.InternalName, columnDetail.DisplayName, columnDetail.Description, columnDetail.Type, columnDetail.ColumnChoices, columnDetail.TypeAsString, columnDetail.Group) { }
/// <summary> /// Checks if a column exists in a list and creates it if it doesn't exist. /// </summary> /// <param name="list">The site to check.</param> /// <param name="columnId">The GUID of the column to use if it needs to be created.</param> /// <param name="columnInternalName">The internal name of the column to check.</param> /// <param name="columnDisplayName">The display name of the column to use if it needs to be created.</param> /// <param name="columnDescription">The description of the column to use if it needs to be created.</param> /// <param name="columnGroup">The column group to add the site column to if it needs to be created.</param> /// <param name="columnXml">The XML definition of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureColumn(this SPList list, Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnTypeAsString, string columnGroup, bool isSiteColumn, ref bool isNewColumn) { ColumnDetails columnDetail = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, string.Empty, columnTypeAsString, columnGroup); return EnsureColumn(list, columnDetail, isSiteColumn, ref isNewColumn); }
public ColumnDetails(ColumnDetails columnDetail) : this(columnDetail.Id, columnDetail.InternalName, columnDetail.DisplayName, columnDetail.Description, columnDetail.Type, columnDetail.ColumnChoices, columnDetail.TypeAsString, columnDetail.Group) { }
/// <summary> /// Checks if a site column exists in a site and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnId">The GUID of the column to use if it needs to be created.</param> /// <param name="columnInternalName">The internal name of the column to check.</param> /// <param name="columnDisplayName">The display name of the column to use if it needs to be created.</param> /// <param name="columnDescription">The description of the column to use if it needs to be created.</param> /// <param name="columnType">The type of the column</param> /// <param name="columnChoices">If the type of the column is choice this is the xml to put in the choices</param> /// <param name="columnGroup">The column group to add the site column to if it needs to be created.</param> /// <param name="columnXml">The XML definition of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureSiteColumn(this SPWeb site, Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnChoices, string columnTypeAsString, string columnGroup, ref bool isNewColumn) { ColumnDetails columnDetail = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, columnChoices, columnTypeAsString, columnGroup); return EnsureSiteColumn(site, columnDetail, ref isNewColumn); }
public ReadOnlyColumnDetails(Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnChoices, string columnTypeAsString, string columnGroup) { _columnDetails = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, columnChoices, columnTypeAsString, columnGroup); }
/// <summary> /// Checks if a site column exists in a site and creates it if it doesn't exist. /// </summary> /// <param name="site">The site to check.</param> /// <param name="columnId">The GUID of the column to use if it needs to be created.</param> /// <param name="columnInternalName">The internal name of the column to check.</param> /// <param name="columnDisplayName">The display name of the column to use if it needs to be created.</param> /// <param name="columnDescription">The description of the column to use if it needs to be created.</param> /// <param name="columnGroup">The column group to add the site column to if it needs to be created.</param> /// <param name="columnXml">The XML definition of the site column.</param> /// <param name="isNewColumn">A boolean that is set to true, if a new column is created; otherwise, it is set to false.</param> /// <returns>A SPField object that references an existing or newly created site column.</returns> public static SPField EnsureSiteColumn(this SPWeb site, Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnTypeAsString, string columnGroup, ref bool isNewColumn) { ColumnDetails columnDetail = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, string.Empty, columnTypeAsString, columnGroup); return(EnsureSiteColumn(site, columnDetail, ref isNewColumn)); }
public ReadOnlyColumnDetails(Guid columnId, string columnInternalName, string columnDisplayName, string columnDescription, SPFieldType columnType, string columnChoices, string columnTypeAsString, string columnGroup) { _columnDetails = new ColumnDetails(columnId, columnInternalName, columnDisplayName, columnDescription, columnType, columnChoices, columnTypeAsString, columnGroup); }