Class FieldAndContentTypeExtensions
This class provides extension methods that will help you work with fields and content types.
Inheritance
Namespace: Microsoft.SharePoint.Client
Assembly: PnP.Framework.dll
Syntax
public static class FieldAndContentTypeExtensions : object
Methods
AddContentTypeToList(List, ContentType, Boolean)
Add content type to list
Declaration
public static bool AddContentTypeToList(this List list, ContentType contentType, bool defaultContent = false)
Parameters
List
list
List to add content type to |
ContentType
contentType
Content type to add to the list |
System.Boolean
defaultContent
If set true, content type is updated to be default content type for the list |
Returns
System.Boolean
|
AddContentTypeToList(Web, String, ContentType, Boolean)
Adds content type to list
Declaration
public static void AddContentTypeToList(this Web web, string listTitle, ContentType contentType, bool defaultContent = false)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list |
ContentType
contentType
Content type to be added to the list |
System.Boolean
defaultContent
If set true, content type is updated to be default content type for the list |
AddContentTypeToListById(List, String, Boolean, Boolean)
Add content type to list
Declaration
public static bool AddContentTypeToListById(this List list, string contentTypeID, bool defaultContent = false, bool searchContentTypeInSiteHierarchy = false)
Parameters
List
list
List to add content type to |
System.String
contentTypeID
Complete ID for the content type |
System.Boolean
defaultContent
If set true, content type is updated to be default content type for the list |
System.Boolean
searchContentTypeInSiteHierarchy
search for content type in site hierarchy |
Returns
System.Boolean
|
AddContentTypeToListById(Web, String, String, Boolean, Boolean)
Adds content type to list
Declaration
public static void AddContentTypeToListById(this Web web, string listTitle, string contentTypeId, bool defaultContent = false, bool searchContentTypeInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list |
System.String
contentTypeId
Complete ID for the content type |
System.Boolean
defaultContent
Optionally make this the default content type |
System.Boolean
searchContentTypeInSiteHierarchy
search for content type in site hierarchy |
AddContentTypeToListByName(List, String, Boolean, Boolean)
Add content type to list
Declaration
public static bool AddContentTypeToListByName(this List list, string contentTypeName, bool defaultContent = false, bool searchContentTypeInSiteHierarchy = false)
Parameters
List
list
List to add content type to |
System.String
contentTypeName
Name of the content type |
System.Boolean
defaultContent
If set true, content type is updated to be default content type for the list |
System.Boolean
searchContentTypeInSiteHierarchy
search for content type in site hierarchy |
Returns
System.Boolean
|
AddContentTypeToListByName(Web, String, String, Boolean, Boolean)
Adds content type to list
Declaration
public static void AddContentTypeToListByName(this Web web, string listTitle, string contentTypeName, bool defaultContent = false, bool searchContentTypeInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list |
System.String
contentTypeName
Name of the content type |
System.Boolean
defaultContent
Optionally make this the default content type |
System.Boolean
searchContentTypeInSiteHierarchy
search for content type in site hierarchy |
AddFieldById(ContentType, Guid, Boolean, Boolean, Boolean, Boolean, Boolean)
Associates field to content type
Declaration
public static void AddFieldById(this ContentType contentType, Guid fieldId, bool required = false, bool hidden = false, bool updateChildren = true, bool showInDisplayForm = true, bool readOnly = false)
Parameters
ContentType
contentType
Content Type to add the field to |
Guid
fieldId
The Id of the field |
System.Boolean
required
True if the field is required |
System.Boolean
hidden
True if the field is hidden |
System.Boolean
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Boolean
showInDisplayForm
Optionally show this field in the display form. |
System.Boolean
readOnly
Optionally make this a read only field. |
AddFieldById(ContentType, String, Boolean, Boolean, Boolean, Boolean, Boolean)
Associates field to content type
Declaration
public static void AddFieldById(this ContentType contentType, string fieldId, bool required = false, bool hidden = false, bool updateChildren = true, bool showInDisplayForm = true, bool readOnly = false)
Parameters
ContentType
contentType
Content Type to add the field to |
System.String
fieldId
String representation of the id of the field (=Guid) |
System.Boolean
required
True if the field is required |
System.Boolean
hidden
True if the field is hidden |
System.Boolean
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Boolean
showInDisplayForm
Optionally show this field in the display form. |
System.Boolean
readOnly
Optionally make this a read only field. |
AddFieldByName(ContentType, String, Boolean, Boolean, Boolean, Boolean, Boolean)
Associates field to content type
Declaration
public static void AddFieldByName(this ContentType contentType, string fieldName, bool required = false, bool hidden = false, bool updateChildren = true, bool showInDisplayForm = true, bool readOnly = false)
Parameters
ContentType
contentType
Content Type to add the field to |
System.String
fieldName
The title or internal name of the field |
System.Boolean
required
True if the field is required |
System.Boolean
hidden
True if the field is hidden |
System.Boolean
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Boolean
showInDisplayForm
Optionally show this field in the display form. |
System.Boolean
readOnly
Optionally make this a read only field. |
AddFieldToContentType(Web, ContentType, Field, Nullable<Boolean>, Nullable<Boolean>, Nullable<Boolean>, Nullable<Boolean>, Nullable<Boolean>)
Associates field to content type
Declaration
public static void AddFieldToContentType(this Web web, ContentType contentType, Field field, bool? required, bool? hidden, bool? updateChildren, bool? showInDisplayForm, bool? readOnly)
Parameters
Web
web
Site to be processed - can be root web or sub site |
ContentType
contentType
Content type to associate field to |
Field
field
Field to associate to the content type |
System.Nullable<System.Boolean>
required
Optionally make this a required field |
System.Nullable<System.Boolean>
hidden
Optionally make this a hidden field |
System.Nullable<System.Boolean>
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Nullable<System.Boolean>
showInDisplayForm
Optionally show this field in the display form. |
System.Nullable<System.Boolean>
readOnly
Optionally make this a read only field. |
AddFieldToContentTypeById(Web, String, String, Boolean, Boolean, Boolean, Boolean, Boolean)
Associates field to content type
Declaration
public static void AddFieldToContentTypeById(this Web web, string contentTypeID, string fieldId, bool required = false, bool hidden = false, bool updateChildren = true, bool showInDisplayForm = true, bool readOnly = false)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
contentTypeID
String representation of the id of the content type to add the field to |
System.String
fieldId
String representation of the field ID (=guid) |
System.Boolean
required
True if the field is required |
System.Boolean
hidden
True if the field is hidden |
System.Boolean
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Boolean
showInDisplayForm
Optionally show this field in the display form. |
System.Boolean
readOnly
Optionally make this a read only field. |
AddFieldToContentTypeByName(Web, String, Guid, Boolean, Boolean, Boolean, Boolean, Boolean)
Associates field to content type
Declaration
public static void AddFieldToContentTypeByName(this Web web, string contentTypeName, Guid fieldID, bool required = false, bool hidden = false, bool updateChildren = true, bool showInDisplayForm = true, bool readOnly = false)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
contentTypeName
Name of the content type |
Guid
fieldID
Guid representation of the field ID |
System.Boolean
required
True if the field is required |
System.Boolean
hidden
True if the field is hidden |
System.Boolean
updateChildren
True to update content types that inherit from the content type; otherwise, false. |
System.Boolean
showInDisplayForm
Optionally show this field in the display form. |
System.Boolean
readOnly
Optionally make this a read only field. |
BestMatch(ContentTypeCollection, ContentTypeId)
Searches for the content type with the closest match to the specified content type ID. If the search finds two matches, the shorter ID is returned.
Declaration
public static ContentTypeId BestMatch(this ContentTypeCollection contentTypes, ContentTypeId contentTypeId)
Parameters
ContentTypeCollection
contentTypes
Content type collection to search |
ContentTypeId
contentTypeId
Content type id for the content type to search |
Returns
ContentTypeId
Content type Id object or null if was not found |
BestMatch(ContentTypeCollection, String)
Searches for the content type with the closest match to the value of the specified content type ID. If the search finds two matches, the shorter ID is returned.
Declaration
public static ContentTypeId BestMatch(this ContentTypeCollection contentTypes, string contentTypeId)
Parameters
ContentTypeCollection
contentTypes
Content type collection to search |
System.String
contentTypeId
Complete ID for the content type to search |
Returns
ContentTypeId
Content type Id object or null if was not found |
BestMatch(ContentTypeId, IEnumerable<ContentType>)
Searches for the content type with the closest match to this content type id. If the search finds two matches, the shorter ID is returned.
Declaration
public static ContentTypeId BestMatch(ContentTypeId contentTypeId, IEnumerable<ContentType> contentTypeCollection)
Parameters
ContentTypeId
contentTypeId
Content type id for the content type to search |
IEnumerable<ContentType>
contentTypeCollection
Content type collection to search |
Returns
ContentTypeId
Content type Id object or null if was not found |
BestMatchContentTypeId(List, String)
Searches the list content types and returns the content type identifier (ID) that is the nearest match to the specified content type ID.
Declaration
public static ContentTypeId BestMatchContentTypeId(this List list, string baseContentTypeId)
Parameters
List
list
The list to check for content types |
System.String
baseContentTypeId
A string with the base content type ID to match. |
Returns
ContentTypeId
The value of the Id property for the content type with the closest match to the value of the specified content type ID. |
Remarks
If the search finds multiple matches, the shorter ID is returned. For example, if 0x0101 is the argument, and the collection contains both 0x010109 and 0x01010901, the method returns 0x010109.
ContentTypeExistsById(List, String)
Does content type exist in list
Declaration
public static bool ContentTypeExistsById(this List list, string contentTypeId)
Parameters
List
list
List to update |
System.String
contentTypeId
Complete ID for the content type |
Returns
System.Boolean
True if the content type exists, false otherwise |
ContentTypeExistsById(Web, String, Boolean)
Does content type exists in the web
Declaration
public static bool ContentTypeExistsById(this Web web, string contentTypeId, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
contentTypeId
Complete ID for the content type |
System.Boolean
searchInSiteHierarchy
Searches accross all content types in the site up to the root site |
Returns
System.Boolean
True if the content type exists, false otherwise |
ContentTypeExistsById(Web, String, String)
Does content type exist in web
Declaration
public static bool ContentTypeExistsById(this Web web, string listTitle, string contentTypeId)
Parameters
Web
web
Web to be processed |
System.String
listTitle
Title of the list to be updated |
System.String
contentTypeId
Complete ID for the content type |
Returns
System.Boolean
True if the content type exists, false otherwise |
ContentTypeExistsByName(List, String)
Does content type exist in list
Declaration
public static bool ContentTypeExistsByName(this List list, string contentTypeName)
Parameters
List
list
List to update |
System.String
contentTypeName
Name of the content type |
Returns
System.Boolean
True if the content type exists, false otherwise |
ContentTypeExistsByName(Web, String, Boolean)
Does content type exists in the web
Declaration
public static bool ContentTypeExistsByName(this Web web, string contentTypeName, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
contentTypeName
Name of the content type |
System.Boolean
searchInSiteHierarchy
Searches accross all content types in the site up to the root site |
Returns
System.Boolean
True if the content type exists, false otherwise |
ContentTypeExistsByName(Web, String, String)
Does content type exist in web
Declaration
public static bool ContentTypeExistsByName(this Web web, string listTitle, string contentTypeName)
Parameters
Web
web
Web to be processed |
System.String
listTitle
Title of the list to be updated |
System.String
contentTypeName
Name of the content type |
Returns
System.Boolean
True if the content type exists, false otherwise |
CreateContentType(Web, String, String, String)
Create new content type to web
Declaration
public static ContentType CreateContentType(this Web web, string name, string id, string group)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
name
Name of the content type |
System.String
id
Complete ID for the content type |
System.String
group
Group for the content type |
Returns
ContentType
Returns newly created content type |
CreateContentType(Web, String, String, String, String, ContentType)
Create new content type to web
Declaration
public static ContentType CreateContentType(this Web web, string name, string description, string id, string group, ContentType parentContentType = null)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
name
Name of the content type |
System.String
description
Description for the content type |
System.String
id
Complete ID for the content type |
System.String
group
Group for the content type |
ContentType
parentContentType
Parent Content Type |
Returns
ContentType
The created content type |
CreateContentTypeFromXML(Web, XDocument)
Create a content type based on the classic feature framework structure.
Declaration
public static ContentType CreateContentTypeFromXML(this Web web, XDocument xDocument)
Parameters
Web
web
Web to operate against |
XDocument
xDocument
Actual XML document |
Returns
ContentType
|
CreateContentTypeFromXMLFile(Web, String)
Create a content type based on the classic feature framework structure.
Declaration
public static ContentType CreateContentTypeFromXMLFile(this Web web, string absolutePathToFile)
Parameters
Web
web
Web to operate against |
System.String
absolutePathToFile
Absolute path to the xml location |
Returns
ContentType
|
CreateContentTypeFromXMLString(Web, String)
Create a content type based on the classic feature framework structure.
Declaration
public static ContentType CreateContentTypeFromXMLString(this Web web, string xmlStructure)
Parameters
Web
web
Web to operate against |
System.String
xmlStructure
XML structure in string format |
Returns
ContentType
|
CreateField(List, FieldCreationInformation, Boolean)
Adds field to a list
Declaration
public static Field CreateField(this List list, FieldCreationInformation fieldCreationInformation, bool executeQuery = true)
Parameters
List
list
List to process |
FieldCreationInformation
fieldCreationInformation
Creation information for the field |
System.Boolean
executeQuery
Optionally skip the executeQuery action |
Returns
Field
The newly created field or existing field. |
CreateField(List, String, Boolean)
Adds a field to a list
Declaration
public static Field CreateField(this List list, string fieldAsXml, bool executeQuery = true)
Parameters
List
list
List to process |
System.String
fieldAsXml
The XML declaration of SiteColumn definition |
System.Boolean
executeQuery
Optionally skip the executeQuery action |
Returns
Field
The newly created field or existing field. |
CreateField(Web, FieldCreationInformation, Boolean)
Create field to web remotely
Declaration
public static Field CreateField(this Web web, FieldCreationInformation fieldCreationInformation, bool executeQuery = true)
Parameters
Web
web
Site to be processed - can be root web or sub site |
FieldCreationInformation
fieldCreationInformation
Creation Information for the field. |
System.Boolean
executeQuery
Optionally skip the executeQuery action |
Returns
Field
The newly created field or existing field. |
CreateField(Web, String, Boolean)
Create field to web remotely
Declaration
public static Field CreateField(this Web web, string fieldAsXml, bool executeQuery = true)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
fieldAsXml
The XML declaration of SiteColumn definition |
System.Boolean
executeQuery
Executes query if true |
Returns
Field
The newly created field or existing field. |
CreateField<TField>(List, FieldCreationInformation, Boolean)
Adds field to a list
Declaration
public static TField CreateField<TField>(this List list, FieldCreationInformation fieldCreationInformation, bool executeQuery = true)
where TField : Field
Parameters
List
list
List to process |
FieldCreationInformation
fieldCreationInformation
Field creation information |
System.Boolean
executeQuery
Optionally skip the executeQuery action |
Returns
TField
The newly created field or existing field. |
Type Parameters
TField
The selected field type to return. |
CreateField<TField>(Web, FieldCreationInformation, Boolean)
Create field to web remotely
Declaration
public static TField CreateField<TField>(this Web web, FieldCreationInformation fieldCreationInformation, bool executeQuery = true)
where TField : Field
Parameters
Web
web
Site to be processed - can be root web or sub site |
FieldCreationInformation
fieldCreationInformation
Field creation information |
System.Boolean
executeQuery
Optionally skip the executeQuery action |
Returns
TField
The newly created field or existing field. |
Type Parameters
TField
The created field type to return. |
CreateFieldsFromXML(Web, XDocument)
Creates field from xml structure which follows the classic feature framework structure
Declaration
public static void CreateFieldsFromXML(this Web web, XDocument xDocument)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
XDocument
xDocument
Actual XML document |
CreateFieldsFromXMLFile(Web, String)
Creates fields from feature element xml file schema. XML file can contain one or many field definitions created using classic feature framework structure.
Declaration
public static void CreateFieldsFromXMLFile(this Web web, string xmlFilePath)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
System.String
xmlFilePath
Absolute path to the xml location |
CreateFieldsFromXMLString(Web, String)
Creates fields from feature element xml file schema. XML file can contain one or many field definitions created using classic feature framework structure.
Declaration
public static void CreateFieldsFromXMLString(this Web web, string xmlStructure)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
System.String
xmlStructure
XML structure in string format |
DeleteContentTypeById(Web, String)
Deletes a content type from the web by id
Declaration
public static void DeleteContentTypeById(this Web web, string contentTypeId)
Parameters
Web
web
Web to delete the content type from |
System.String
contentTypeId
Id of the content type to delete |
DeleteContentTypeByName(Web, String)
Deletes a content type from the web by name
Declaration
public static void DeleteContentTypeByName(this Web web, string contentTypeName)
Parameters
Web
web
Web to delete the content type from |
System.String
contentTypeName
Name of the content type to delete |
FieldExistsById(List, Guid)
Returns if the field is found
Declaration
public static bool FieldExistsById(this List list, Guid fieldId)
Parameters
List
list
List to process |
Guid
fieldId
Guid of the field ID |
Returns
System.Boolean
True if the fields exists, false otherwise |
FieldExistsById(List, String)
Returns if the field is found, query based on the ID
Declaration
public static bool FieldExistsById(this List list, string fieldId)
Parameters
List
list
List to process |
System.String
fieldId
String representation of the field ID (=guid) |
Returns
System.Boolean
True if the fields exists, false otherwise |
FieldExistsById(Web, Guid, Boolean)
Returns if the field is found
Declaration
public static bool FieldExistsById(this Web web, Guid fieldId, bool searchInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
Guid
fieldId
Guid for the field ID |
System.Boolean
searchInSiteHierarchy
If true, search parent sites and root site |
Returns
System.Boolean
True or false depending on the field existence |
FieldExistsById(Web, String, Boolean)
Does field exist in web
Declaration
public static bool FieldExistsById(this Web web, string fieldId, bool searchInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
System.String
fieldId
String representation of the field ID (=guid) |
System.Boolean
searchInSiteHierarchy
If true, search parent sites and root site |
Returns
System.Boolean
True if exists, false otherwise |
FieldExistsByName(List, String)
Field exists in list by name
Declaration
public static bool FieldExistsByName(this List list, string fieldName)
Parameters
List
list
List to process |
System.String
fieldName
Internal name of the field |
Returns
System.Boolean
True if the fields exists, false otherwise |
FieldExistsByName(Web, String, Boolean)
Returns if the field is found
Declaration
public static bool FieldExistsByName(this Web web, string fieldName, bool searchInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
System.String
fieldName
String for the field internal name to be used as query criteria |
System.Boolean
searchInSiteHierarchy
If true, search parent sites and root site |
Returns
System.Boolean
True or false depending on the field existence |
FieldExistsByNameInContentType(ContentType, String)
Checks if a field exists in a content type by id
Declaration
public static bool FieldExistsByNameInContentType(this ContentType contentType, string fieldName)
Parameters
ContentType
contentType
The content type to check |
System.String
fieldName
The name of the field to look for |
Returns
System.Boolean
True if field exists in content type, otherwise false |
FieldExistsByNameInContentType(Web, String, String)
Field exists in content type
Declaration
public static bool FieldExistsByNameInContentType(this Web web, string contentTypeName, string fieldName)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
System.String
contentTypeName
Name of the content type |
System.String
fieldName
Name of the field |
Returns
System.Boolean
True if exists, false otherwise |
FormatFieldXml(FieldCreationInformation)
Formats a fieldcreationinformation object into Field CAML xml.
Declaration
public static string FormatFieldXml(FieldCreationInformation fieldCreationInformation)
Parameters
FieldCreationInformation
fieldCreationInformation
Field Cration Information object |
Returns
System.String
|
GetAllowDeletion(Field)
Gets the AllowDeletion property from a field.
Note 1: This method will load field
.SchemaXmlWithResourceTokens if not any of the properties field
.SchemaXmlWithResourceTokens or field
.SchemaXml is already loaded by the caller.
Declaration
public static bool? GetAllowDeletion(this Field field)
Parameters
Field
field
Field to be processed |
Returns
System.Nullable<System.Boolean>
Returns false if field deletion is not allowed, true if field deletion is allowed, and null if the field default behavior is used to determine if field deletion is allowed. |
GetContentTypeById(List, String)
Return content type by Id
Declaration
public static ContentType GetContentTypeById(this List list, string contentTypeId)
Parameters
List
list
List to update |
System.String
contentTypeId
Complete ID for the content type |
Returns
ContentType
Content type object or null if was not found |
GetContentTypeById(Web, String, Expression<Func<ContentTypeCollection, Object>>, Boolean)
Return content type by Id
Declaration
public static ContentType GetContentTypeById(this Web web, string contentTypeId, Expression<Func<ContentTypeCollection, object>> retrievals, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
contentTypeId
Complete ID for the content type |
Expression<Func<ContentTypeCollection, System.Object>>
retrievals
Specify additional data to load when retrieving the content types |
System.Boolean
searchInSiteHierarchy
Searches accross all content types in the site up to the root site |
Returns
ContentType
Content type object or null if was not found |
GetContentTypeById(Web, String, Boolean)
Return content type by Id
Declaration
public static ContentType GetContentTypeById(this Web web, string contentTypeId, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
contentTypeId
Complete ID for the content type |
System.Boolean
searchInSiteHierarchy
Searches accross all content types in the site up to the root site |
Returns
ContentType
Content type object or null if was not found |
GetContentTypeByName(List, String)
Return content type by name
Declaration
public static ContentType GetContentTypeByName(this List list, string contentTypeName)
Parameters
List
list
List to update |
System.String
contentTypeName
Name of the content type |
Returns
ContentType
Content type object or null if was not found |
GetContentTypeByName(Web, String, Boolean)
Return content type by name
Declaration
public static ContentType GetContentTypeByName(this Web web, string contentTypeName, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
contentTypeName
Name of the content type |
System.Boolean
searchInSiteHierarchy
Searches accross all content types in the site up to the root site |
Returns
ContentType
Content type object or null if was not found |
GetDefaultColumnValueFromField(Field, ClientContext, String, String[])
Declaration
public static IDefaultColumnValue GetDefaultColumnValueFromField(this Field field, ClientContext clientContext, string folderRelativePath, string[] value)
Parameters
Field
field
|
ClientContext
clientContext
|
System.String
folderRelativePath
|
System.String[]
value
|
Returns
IDefaultColumnValue
|
GetFieldById(List, Guid)
Returns the field if it exists. Null if it does not exist.
Declaration
public static Field GetFieldById(this List list, Guid fieldId)
Parameters
List
list
List to be processed. Columns assoc in lists are defined on web or rootweb. |
Guid
fieldId
Guid for the field ID |
Returns
Field
Field |
GetFieldById(Web, Guid, Boolean)
Returns the field if it exists. Null if it does not exist.
Declaration
public static Field GetFieldById(this Web web, Guid fieldId, bool searchInSiteHierarchy = false)
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
Guid
fieldId
Guid for the field ID |
System.Boolean
searchInSiteHierarchy
If true, search parent sites and root site |
Returns
Field
Field of type TField |
GetFieldById<TField>(List, Guid)
Returns the field if it exists. Null if it does not exist.
Declaration
public static TField GetFieldById<TField>(this List list, Guid fieldId)
where TField : Field
Parameters
List
list
List to be processed. Columns assoc in lists are defined on web or rootweb. |
Guid
fieldId
Guid for the field ID |
Returns
TField
Field of type TField |
Type Parameters
TField
The selected field type to return. |
GetFieldById<TField>(Web, Guid, Boolean)
Returns the field if it exists. Null if it does not exist.
Declaration
public static TField GetFieldById<TField>(this Web web, Guid fieldId, bool searchInSiteHierarchy = false)
where TField : Field
Parameters
Web
web
Site to be processed - can be root web or sub site. Site columns should be created to root site. |
Guid
fieldId
Guid for the field ID |
System.Boolean
searchInSiteHierarchy
If true, search parent sites and root site |
Returns
TField
Field of type TField |
Type Parameters
TField
The selected field type to return. |
GetFieldByInternalName(FieldCollection, String)
Returns the field if it exists. Null if it does not exist.
Declaration
public static Field GetFieldByInternalName(this FieldCollection fields, string internalName)
Parameters
FieldCollection
fields
FieldCollection to be processed. |
System.String
internalName
Internal name of the field |
Returns
Field
Field |
GetFieldByInternalName(Web, String, Boolean)
Returns the field if it exists. Null if does not exist.
Declaration
public static Field GetFieldByInternalName(this Web web, string internalName, bool searchInSiteHierarchy = false)
Parameters
Web
web
Web to be processed |
System.String
internalName
If true, search parent sites and root site |
System.Boolean
searchInSiteHierarchy
If true, search across all the available fields in the site hierarchy |
Returns
Field
Field |
GetFieldByInternalName<TField>(FieldCollection, String)
Returns the field if it exists. Null if it does not exist.
Declaration
public static TField GetFieldByInternalName<TField>(this FieldCollection fields, string internalName)
where TField : Field
Parameters
FieldCollection
fields
FieldCollection to be processed. |
System.String
internalName
Internal name of the field |
Returns
TField
Field of type TField |
Type Parameters
TField
The selected field type to return. |
GetFieldByName(FieldCollection, String)
Returns the field if it exists. Null if it does not exist.
Declaration
public static Field GetFieldByName(this FieldCollection fields, string internalName)
Parameters
FieldCollection
fields
FieldCollection to be processed. |
System.String
internalName
Guid for the field ID |
Returns
Field
Field |
GetFieldByName<TField>(FieldCollection, String)
Returns the field if it exists. Null if it does not exist.
Declaration
public static TField GetFieldByName<TField>(this FieldCollection fields, string internalName)
where TField : Field
Parameters
FieldCollection
fields
FieldCollection to be processed. |
System.String
internalName
Guid for the field ID |
Returns
TField
Field of type TField |
Type Parameters
TField
The selected field type to return. |
GetFields(List, String[])
Gets a list of fields from a list by names.
Declaration
public static IEnumerable<Field> GetFields(this List list, params string[] fieldInternalNames)
Parameters
List
list
The target list containing the fields. |
System.String[]
fieldInternalNames
List of field names to retreieve. |
Returns
IEnumerable<Field>
List of fields requested. |
GetIsAllowedInContentTypeOrder(ContentType)
Checks if the content type is allowed to be set in the content type order.
Declaration
public static bool GetIsAllowedInContentTypeOrder(this ContentType contentType)
Parameters
ContentType
contentType
Target content type to check |
Returns
System.Boolean
|
GetParentIdValue(ContentTypeId)
Calculates the parent content type id
Declaration
public static string GetParentIdValue(this ContentTypeId contentTypeId)
Parameters
ContentTypeId
contentTypeId
Content type id to calculate the parent content type id from |
Returns
System.String
|
HideContentTypesInNewButton(List, IList<ContentType>)
Hides the specified content types in the list new button. Existing visibility and content type order is not altered.
Declaration
public static void HideContentTypesInNewButton(this List list, IList<ContentType> contentTypes)
Parameters
List
list
Target list containing the content types |
IList<ContentType>
contentTypes
Content types to hide |
Remarks
Content types specified in contentTypes
needs to be the actual content type in the list and not it's parent.
IsChildOf(ContentTypeId, ContentTypeId)
Calculates if a content type id is a child of another content type id
Declaration
public static bool IsChildOf(this ContentTypeId current, ContentTypeId contentTypeId)
Parameters
ContentTypeId
current
Parent content type id |
ContentTypeId
contentTypeId
Content type id to check |
Returns
System.Boolean
|
IsParentOf(ContentTypeId, ContentTypeId)
Calculates if a content type id is a parent of another content type id
Declaration
public static bool IsParentOf(this ContentTypeId current, ContentTypeId contentTypeId)
Parameters
ContentTypeId
current
Child content type id |
ContentTypeId
contentTypeId
Content type id to check |
Returns
System.Boolean
|
RemoveContentTypeFromList(Web, List, ContentType)
Removes content type from a list
Declaration
public static void RemoveContentTypeFromList(this Web web, List list, ContentType contentType)
Parameters
Web
web
Site to be processed - can be root web or sub site |
List
list
The List |
ContentType
contentType
The Content Type |
RemoveContentTypeFromListById(Web, List, String)
Removes content type from a list
Declaration
public static void RemoveContentTypeFromListById(this Web web, List list, string contentTypeId)
Parameters
Web
web
Site to be processed - can be root web or sub site |
List
list
The List |
System.String
contentTypeId
Complete ID for the content type |
RemoveContentTypeFromListById(Web, String, String)
Removes content type from a list
Declaration
public static void RemoveContentTypeFromListById(this Web web, string listTitle, string contentTypeId)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list |
System.String
contentTypeId
Complete ID for the content type |
RemoveContentTypeFromListByName(Web, List, String)
Removes content type from list
Declaration
public static void RemoveContentTypeFromListByName(this Web web, List list, string contentTypeName)
Parameters
Web
web
Site to be processed - can be root web or sub site |
List
list
The List |
System.String
contentTypeName
The name of the content type |
RemoveContentTypeFromListByName(Web, String, String)
Removes content type from list
Declaration
public static void RemoveContentTypeFromListByName(this Web web, string listTitle, string contentTypeName)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list |
System.String
contentTypeName
The name of the content type |
RemoveFieldById(Web, String)
Removes a field by specifying its ID
Declaration
public static void RemoveFieldById(this Web web, string fieldId)
Parameters
Web
web
Web to process |
System.String
fieldId
The id of the field to remove |
RemoveFieldByInternalName(Web, String)
Removes a field by specifying its internal name
Declaration
public static void RemoveFieldByInternalName(this Web web, string internalName)
Parameters
Web
web
Web to process |
System.String
internalName
Internal name of the field |
ReorderContentTypes(List, IEnumerable<String>)
Reorders content types on the list. The first one in the list is the default item. Any items left out from the list will still be on the content type, but will not be visible on the new button.
Declaration
public static void ReorderContentTypes(this List list, IEnumerable<string> contentTypeNamesOrIds)
Parameters
List
list
Target list containing the content types |
IEnumerable<System.String>
contentTypeNamesOrIds
Content type names or ids to sort. |
SetAllowDeletion(Field, Nullable<Boolean>)
Sets the AllowDeletion property on a field.
Note 1: This method will load field
.SchemaXmlWithResourceTokens if it's not already loaded by the caller.
Note 2: This method does not update the field nor execute the query.
Declaration
public static void SetAllowDeletion(this Field field, bool? AllowDeletion)
Parameters
Field
field
Field to be processed |
System.Nullable<System.Boolean>
AllowDeletion
False blocks field deletion, True enables field deletion. Null uses field default behavior. |
SetDefaultContentType(List, ContentTypeId)
Sets the default content type in a list.
Declaration
public static void SetDefaultContentType(this List list, ContentTypeId contentTypeId)
Parameters
List
list
Target list containing the content type |
ContentTypeId
contentTypeId
Id of the list content type to make default. |
Remarks
Content type specified in contentTypeId
needs to be
the id of the actual content type in the list and not it's parent.
SetDefaultContentType(List, String)
Sets the default content type in a list.
Declaration
public static void SetDefaultContentType(this List list, string contentTypeId)
Parameters
List
list
Target list containing the content type |
System.String
contentTypeId
Id of the list content type to make default. |
Remarks
Content type specified in contentTypeId
needs to be
the id of the actual content type in the list and not it's parent.
SetDefaultContentTypeToList(List, ContentType)
Set default content type to list
Declaration
public static void SetDefaultContentTypeToList(this List list, ContentType contentType)
Parameters
List
list
List to update |
ContentType
contentType
Content type to make default |
SetDefaultContentTypeToList(List, String)
Set's default content type list.
Declaration
public static void SetDefaultContentTypeToList(this List list, string contentTypeId)
Parameters
List
list
List to update |
System.String
contentTypeId
Complete ID for the content type |
Remarks
Notice. Currently removes other content types from the list. Known issue
SetDefaultContentTypeToList(Web, List, ContentType)
Set default content type to list
Declaration
public static void SetDefaultContentTypeToList(this Web web, List list, ContentType contentType)
Parameters
Web
web
Site to be processed - can be root web or sub site |
List
list
List to update |
ContentType
contentType
Content type to make default |
SetDefaultContentTypeToList(Web, List, String)
Set default content type to list
Declaration
public static void SetDefaultContentTypeToList(this Web web, List list, string contentTypeId)
Parameters
Web
web
Site to be processed - can be root web or sub site |
List
list
List to update |
System.String
contentTypeId
Complete ID for the content type |
SetDefaultContentTypeToList(Web, String, ContentType)
Set's default content type list.
Declaration
public static void SetDefaultContentTypeToList(this Web web, string listTitle, ContentType contentType)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list to be updated |
ContentType
contentType
Content type to make default |
SetDefaultContentTypeToList(Web, String, String)
Set default content type to list
Declaration
public static void SetDefaultContentTypeToList(this Web web, string listTitle, string contentTypeId)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
listTitle
Title of the list to be updated |
System.String
contentTypeId
Complete ID for the content type |
SetJsLinkCustomizations(Field, String)
Adds jsLink to a field.
Declaration
public static void SetJsLinkCustomizations(this Field field, string jsLink)
Parameters
Field
field
The field to add jsLink to |
System.String
jsLink
JSLink to set to the form. Set to empty string to remove the set JSLink customization. Specify multiple values separated by pipe symbol. For e.g.: ~sitecollection/_catalogs/masterpage/jquery-2.1.0.min.js|~sitecollection/_catalogs/masterpage/custom.js |
SetJsLinkCustomizations(List, String, String)
Adds jsLink to a list field.
Declaration
public static void SetJsLinkCustomizations(this List list, string fieldName, string jsLink)
Parameters
List
list
The list where the field exists. |
System.String
fieldName
The field to add jsLink to. |
System.String
jsLink
JSLink to set to the form. Set to empty string to remove the set JSLink customization. Specify multiple values separated by pipe symbol. For e.g.: ~sitecollection/_catalogs/masterpage/jquery-2.1.0.min.js|~sitecollection/_catalogs/masterpage/custom.js |
SetLocalizationForContentType(ContentType, String, String, String)
Set localized labels for content type
Declaration
public static void SetLocalizationForContentType(this ContentType contentType, string cultureName, string nameResource, string descriptionResource)
Parameters
ContentType
contentType
Name of the content type |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
nameResource
Localized value for the Name property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForContentType(List, String, String, String, String)
Set localized labels for content type
Declaration
public static void SetLocalizationForContentType(this List list, string contentTypeId, string cultureName, string nameResource, string descriptionResource)
Parameters
List
list
List to update |
System.String
contentTypeId
Complete ID for the content type |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
nameResource
Localized value for the Name property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForContentType(Web, String, String, String, String)
Set localized labels for content type
Declaration
public static void SetLocalizationForContentType(this Web web, string contentTypeName, string cultureName, string nameResource, string descriptionResource)
Parameters
Web
web
Web to operate on |
System.String
contentTypeName
Name of the content type |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
nameResource
Localized value for the Name property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(Field, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this Field field, string cultureName, string titleResource, string descriptionResource)
Parameters
Field
field
Field to update |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(List, Field, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this List list, Field siteColumn, string cultureName, string titleResource, string descriptionResource)
Parameters
List
list
List to update |
Field
siteColumn
Site column to update |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(List, Guid, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this List list, Guid siteColumnId, string cultureName, string titleResource, string descriptionResource)
Parameters
List
list
List to update |
Guid
siteColumnId
Guid of the site column ID |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(List, String, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this List list, string siteColumnName, string cultureName, string titleResource, string descriptionResource)
Parameters
List
list
List to update |
System.String
siteColumnName
Name of the site column |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(Web, Field, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this Web web, Field siteColumn, string cultureName, string titleResource, string descriptionResource)
Parameters
Web
web
Web to operate on |
Field
siteColumn
Site column to localize |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(Web, Guid, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this Web web, Guid siteColumnId, string cultureName, string titleResource, string descriptionResource)
Parameters
Web
web
Web to operate on |
Guid
siteColumnId
Guid with the site column ID |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
SetLocalizationForField(Web, String, String, String, String)
Set localized labels for field
Declaration
public static void SetLocalizationForField(this Web web, string siteColumnName, string cultureName, string titleResource, string descriptionResource)
Parameters
Web
web
Web to operate on |
System.String
siteColumnName
Name of the site column |
System.String
cultureName
Culture for the localization (en-es, nl-be, fi-fi,...) |
System.String
titleResource
Localized value for the Title property |
System.String
descriptionResource
Localized value for the Description property |
ShowContentTypesInNewButton(List, IList<ContentType>)
Makes the specified content types visible in the list new button. Existing visibility and content type order is not altered.
Declaration
public static void ShowContentTypesInNewButton(this List list, IList<ContentType> contentTypes)
Parameters
List
list
Target list containing the content types |
IList<ContentType>
contentTypes
List content types to make visible |
Remarks
Content types specified in contentTypes
needs to be the actual content type in the list and not it's parent.
UpdateContentTypeById(Web, String, String, String, String, String, String, String, String, Nullable<Boolean>)
Update existing content type of a web
Declaration
public static ContentType UpdateContentTypeById(this Web web, string Id, string newContentTypeName = "", string description = "", string group = "", string displayFormUrl = "", string newFormUrl = "", string editFormUrl = "", string documentTemplate = "", bool? hidden = null)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
Id
Id of the content type |
System.String
newContentTypeName
Updated name of the content type |
System.String
description
Description for the content type |
System.String
group
Group for the content type |
System.String
displayFormUrl
Display form url of the content type |
System.String
newFormUrl
New form url of the content type |
System.String
editFormUrl
Edit form url of the content type |
System.String
documentTemplate
Document template of the content type |
System.Nullable<System.Boolean>
hidden
Toggle value indicating whether content type should be hidden or not |
Returns
ContentType
The updated content type |
UpdateContentTypeByName(Web, String, String, String, String, String, String, String, String, Nullable<Boolean>)
Update existing content type of a web
Declaration
public static ContentType UpdateContentTypeByName(this Web web, string name, string newContentTypeName = "", string description = "", string group = "", string displayFormUrl = "", string newFormUrl = "", string editFormUrl = "", string documentTemplate = "", bool? hidden = null)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
name
Name of the content type |
System.String
newContentTypeName
Updated name of the content type |
System.String
description
Description for the content type |
System.String
group
Group for the content type |
System.String
displayFormUrl
Display form url of the content type |
System.String
newFormUrl
New form url of the content type |
System.String
editFormUrl
Edit form url of the content type |
System.String
documentTemplate
Document template of the content type |
System.Nullable<System.Boolean>
hidden
Toggle value indicating whether content type should be hidden or not |
Returns
ContentType
The updated content type |