• 3 ways for adding new column in SharePoint list

    by  • May 12, 2010 • MOSS 2007, PowerShell, SharePoint 2010 • 1 Comment

    In this post we will see 3 different methods for adding columns in SharePoint list or document library or discussion board.

    using browser
    Go to the list which you want to add column
    On the page that displays the list, click list’s settings and create columns.
    Type a name for the column, choose the column type and click OK.

    using Object model

    
    SPSite site = new SPSite(siteUrl);
    SPWeb web = site.OpenWeb();
    
    site.AllowUnsafeUpdates = true;
    web.AllowUnsafeUpdates = true;
    
    SPList list = web.Lists["mylist"];
    SPFieldText fldName = (SPFieldText)list.Fields.CreateNewField(SPFieldType.Text.ToString(), "mycolumn");
    fldName.Required = true;
    fldName.MaxLength = 50;
    list.Fields.Add(fldName);
    list.Update();
    
    site.AllowUnsafeUpdates = false;
    web.AllowUnsafeUpdates = false;
    

    using PowerShell

    
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $site= New-Object Microsoft.SharePoint.SPSite ("http://mysite")
    $web=$site.OpenWeb()
    $list=$web.Lists["mylist"]
    $list.Fields.Add("mycolumn", "Text", 0)
    

    About

    Hojo Clement was working in US Technology in Trivandrum as a Senior Software Engineer. He hasĀ 6 years experience in working with Web Development Technologies inlcuding MOSS and ASP.net.

    One Response to 3 ways for adding new column in SharePoint list

    1. Rogue
      October 6, 2010 at 10:30 am

      Wanted to know how to create a multiline text field in a list or a library..needed help urgently..

    Leave a Reply

    Your email address will not be published. Required fields are marked *