Want to create a list in sharepoint which contains NEWS and DATE programmatically.

so please help me and provide me the code for it.

  • what you need here.have you created a list or do you want to create a list also programmatically? – Hardik Kothari Sep 20 '14 at 5:05

You can use following code to add list in sharepoint programmatically.

public void createList()
    // choose your site
    SPSite site = new SPSite("http://merdev-moss:5050");
    SPWeb web = site.OpenWeb();
    SPListCollection lists = web.Lists;
    // create new Generic list called "My List"
    lists.Add("My List", "My list Description", SPListTemplateType.GenericList);

    SPList newList = web.Lists["My List"];
    // create Text type new column called "My Column"
    newList.Fields.Add("My Column", SPFieldType.Text, true);
    /*create lookup type new column called "Lookup Column"
    * Here I am going to get the information from the "Title"
    * column of a list called "User Roles"
    SPList targetList = web.Lists["User Roles"];
    newList.Fields.AddLookup("Lookup Column", targetList.ID, false);
    SPFieldLookup lkp = (SPFieldLookup)newList.Fields["Lookup Column"];
    lkp.LookupField = targetList.Fields["Title"].InternalName;
    // make new column visible in default view
    SPView view = newList.DefaultView;
    view.ViewFields.Add("My Column");
    view.ViewFields.Add("Lookup Column");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.