Sharepoint Genesis how to create basic lists Tutorial and example

1 - make your Fields:
/// <summary>
/// My Field
/// </summary>
[SPGENField(
ID = "{copy paste a guid here}",
StaticName = "MyFieldName",
InternalName = "MyFieldName",
DisplayName = "$Resources:MyResource,Field_MyFieldName_DisplayName;",
Type = SPFieldType.Text,
Group = "$Resources:BoiModel,FieldGroup_MySite_Title;",
Required = false)]
public class MyFieldName : SPGENField<MyFieldName, SPFieldNumber, string>{}

2 - make your Content Type:
/// <summary>
/// My Content Type
/// </summary>
[SPGENContentType(
ID = "0x0100574F3398A6A141B4A6E0F56CF5B58C1B => this is from http://spgenesis.codeplex.com/wikipage?title=Content%20type",
Name = "$Resources:MySiteModel,ContentType_MySite_Name;",
Group = "$Resources:MySiteModel,Group_MySiteContentTypes")]
public class MyContentType : SPGENContentType<MyContentType>
{   protected override void InitializeDefinition(SPGENContentTypeProperties properties)
 
     properties.FieldLinks.ProvisioningMode =
SPGENProvisioningMode.AddUpdateRemoveExclusive;
     properties.FieldLinks.Add<Fields.MyFieldName>();
     properties.FieldLinks.Add<Fields.MyOtherFieldName>();
  }
}


3 - make your List:
[SPGENListInstance(
WebRelURL = "Lists/MyList",
Title = "$Resources:MySiteModel,ListInstance_MyList_Title;",
TemplateType = (int)SPListTemplateType.GenericList,
OnQuickLaunch = false,
ContentTypesEnabled = true)]
public class MyList : SPGENListInstance<MyList>
{   //Here we declare that this list instance will use our content type
  protected override void InitializeDefinition(SPGENListInstanceProperties properties)
 
     properties.ContentTypes.ProvisioningMode =
SPGENProvisioningMode.AddUpdateRemoveExclusive;
     properties.ContentTypes.Add<ContentTypes.MyContentType>();
  }
  protected override void OnProvisionFinalized(SPList list)
  {     base.OnProvisionFinalized(list);
    ModelUtilities.SetDefaultView(list);
  }
}

3.5 - :
class ModelUtilities
{   public static void SetDefaultView(SPList list)
  {     SPView view = list.DefaultView;
    SPContentType ct = list.ContentTypes[0];
    view.ViewFields.DeleteAll();     for (int i = 1; i < ct.FieldLinks.Count; i++)
       view.ViewFields.Add(ct.FieldLinks[i].Name);
    view.Update();
  }
}


4 - Provisions!!! (per field, content type and list):
Fields.MyFieldName.Instance.Provision(web);
ContentTypes.MyContentType.Instance.Provision(web);
Lists.MyList.Instance.Provision(web);

Comments

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem