sharepointsharepoint-2010sharepointfoundation2010sharepoint-object-model

Sharepoint 2010 - make Title, Description and Keyword fields as required fields in Picture Library using server-object-model


I'm creating a Sharepoint feature, this feature has an event receiver associated to it. In the event receiver, I'm creating a Document Library and Picture Library using server-side object model. I'm also adding new custom columns (around 80) to these newly created document and picture library. Now I want to modify the properties of the Description, Keywords and Title fields that are by default created along with the picture library. I want to make these fields as Required fields. How do I do this? I tried to set SPList.AllowContentTypes = true and try to change the attributes of these fields, but it doesn't work (neither gives an error nor makes these required fields). I also tried to access the content types and try to change the attributes using SPContentType.FieldsLinks["Column_name"].Required and SPContentType.Fields["Column_name"].Required but it gives me an error. Does anyone have any other suggestions?


Solution

  • Here is the answer....

    SPContentType ct = mypiclib.ContentTypes["Picture"];
    SPFieldLinks titleLink = ct.FieldLinks["Title"];
    SPFieldLinks descLink = ct.FieldLinks["comments"]; //internal name of Description
    SPFieldLinks keywords = ct.FieldLinks["keywords"];
    titlelink.Required = true;
    descLink.Required = true;
    keywords.Required = true;
    ct.Update();