Skip to content

Latest commit

 

History

History

README.md

Content Types

Manage content types on a SharePoint site — create, update, delete, add and remove fields, reorder fields, and associate with lists.


Prerequisites

Requirement Description Reference
Site Owner or Site Collection Administrator role Required to create, update, and delete content types at the site level. SharePoint admin roles
Site Columns (fields) must exist on the site Needed when adding fields to a content type. Field examples

How content types work

graph TD
    subgraph Site
        CT["Content Type"]
        CT --> FL["Field Links (ordered)"]
        FL --> F1["Field: Title"]
        FL --> F2["Field: Editor"]
        FL --> F3["Field: CustomColumn"]
    end

    subgraph List
        L["Document Library"]
        L -->|has| CTs["Content Types"]
        CTs --> D["Default CT"]
        CTs --> O["Other CTs"]
    end

    CT -.->|add to| L
Loading

A content type lives at the site level and defines a reusable set of columns (fields) with their display order (field links). It can then be associated with one or more lists.


Examples

Workflow

Operation File Required role API reference
End-to-end: create → add field → add to list → verify basic_usage.py Site Owner Full workflow

Site-level content types

Operation File Required role API reference
List content types (site or list scope) list_all.py Read access Content type collection
Get a content type by name or id get.py Read access Get content type
Create a content type create.py Site Owner Create
Create a content type from a parent create_from_parent.py Site Owner Create with parent
Update a content type (description, group) update.py Site Owner Update
Add a site column to a content type add_field.py Site Owner Add field link
Remove a field from a content type remove_field.py Site Owner Remove field link
Reorder fields in a content type reorder_fields.py Site Owner Reorder fields
Delete a content type delete.py Site Owner Delete

List association

Operation File Required role API reference
Create a content type and add it to a list add_to_list.py Site Owner on target list Add to list
Add an existing site content type to a list add_available_to_list.py Site Owner on target list Add available CT
Set the default content type for a list set_default.py Site Owner on target list Set default

Quick start

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.contenttypes.creation_information import ContentTypeCreationInformation

ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_secret(
    "contoso.onmicrosoft.com", "client_id", "client_secret"
)

# List all content types
cts = ctx.web.content_types.get().execute_query()
for ct in cts:
    print(f"  {ct.name}  (ID: {ct.id})")

# Create a new content type
info = ContentTypeCreationInformation(Name="Project Document", Description="For Contoso projects")
ct = ctx.web.content_types.add(info).execute_query()
print(f"Created: {ct.name}")

API reference