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

README.md

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")]
[ContentType("0x01006B62A92F6C8B4470A0EC3E9DDAC6EBB1")]
public interface IBugReport
{
    //Standard fields can be used
    [TextField(InternalName="Title")]
    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
    [UserField]
    Int32 UsersReponsible { get; set; }

    //But there's a lot more to set if you need to
    [DefaultValue("Open")
    [Title(Title = "Bug status")]
    [Description(DescriptionResource = "Field_Staus_Description")]
    [Required(true)]
    [ChoiceField(false)]
    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");
    }

    [List]
    [Title(TitleResource="List_ProjectAReports_Title")]
    public EntitySet<BugReport> ReportsA { get; set; }

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

Install

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