Skip to content
SHAPES - SharePoint code-first data structures and repository
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

SHAPES - SharePoint Entities

Code first approach for provisioning SharePoint data structures using CSOM.

Define content types and fields

//Multi-language support in Office 365
[Title(TitleResource = "ContentType_BugReport_Title")]
public interface IBugReport
    //Standard fields can be used
    String Title { get; set; }

    //If internal name is not specified, property name will be used instead
    [NoteField(RichText = false)]
    String Description { get; set; }

    [LookupField(false, "Lists/Reports")]
    Int32 Report { get; set; }
    //It's enough to specify field type
    Int32 UsersReponsible { get; set; }

    //But there's a lot more to set if you need to
    [Title(Title = "Bug status")]
    [Description(DescriptionResource = "Field_Staus_Description")]
    Status Status { get; set; }

//Enum can be used as a list of choice values
public enum Status { Open, Closed }

Define list

public class BugReport : IBugReport
    String Title { get; set; }
    String Description { get; set; }
    Int32 Report { get; set; }
    Int32 UsersReponsible { get; set; }
    Status Status { get; set; }

Create context

public class Entities : EntityContext
    public Entities(ClientContext context) : base(context)
        Configuration = new AppSettingsEntityConfiguration();
        //Define resuorce file and supported languages
        ResourceProvider = new ResourceProvider(typeof(Resources.Structures), "en", "de-DE", "pl-PL");

    public EntitySet<BugReport> ReportsA { get; set; }

    //Reuse definition in multiple instances
    [List, Title(TitleResource="List_ProjectBReports_Title")]
    public EntitySet<BugReport> ReportsB { get; set; }


var entities = new Entities(clientContext);
//Installation to restores desired state and won't create duplicates. It's safe to execute it multiple times.
You can’t perform that action at this time.