I have list name students with 2 columns First Name and Last Name and has data in the list. I want to add a new column "class" to the students list. what to do in using visual studio.

Is it the right process or is there any better procedure to deal with the lists in SharePoint ??


You can add that column directly from the Sharepoint list itself enter image description here

However to add it using Visual Studio refer following code

using (SPSite oSPsite = new SPSite("http://Web-URL"))
    oSPsite.AllowUnsafeUpdates = true;

    using (SPWeb oSPWeb = oSPsite.OpenWeb())
        oSPWeb.AllowUnsafeUpdates = true;

        /* get the SPList object by list name*/
        SPList lst = oSPWeb.Lists["student"];

      /* create a Class field */
        SPFieldText fldName = (SPFieldText)lst.Fields.CreateNewField(
                        SPFieldType.Text.ToString(), "Class");
        fldName.Required = true;
        fldName.MaxLength = 50;

       /* add the new fields to the list */

      /* finally update list */

        oSPWeb.AllowUnsafeUpdates = false;

    oSPsite.AllowUnsafeUpdates = false;
| improve this answer | |

You can create column in List without Visual Studio.

from GUI you can follow these steps:

  1. In the ribbon, click the List or Library tab.
  2. In the Manage Views group, click Create Column.
  3. In the Name and Type section, type the name that you want for the column in the Column name box.
  4. Under The type of information in this column is, select the type of information that you want to appear in the column.
  5. In the Additional Column Settings section, type a description in the Description box to help people understand the purpose of the column and what data it should contain. This description is optional.

Depending on the type of column that you selected, more options may appear in the Additional Column Settings section. Select the additional settings that you want.

  1. If you want the data in the column validated, click Column Validation to expand, and type the Formula that you want to use to validate the data, and type the User message that you want to provide users to help them type valid data. The Column Validation section is not available for all types of columns.
  2. Click OK.


| improve this answer | |

You can use SharePoint designer to quickly and easily add columns to a list, if you have it installed.

  1. Open your site in SharePoint Designer
  2. From the left click Lists and Libraries
  3. Select the relevant list
  4. Click Edit List Columns under the Customization section
  5. From the ribbon at the top choose Add New Column
| improve this answer | |

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.