Welcome to Office & SharePoint Pro Sign in | Join | Help
in Search

SUBSCRIBE to Windows IT Pro Magazine & SAVE 30%      FREE Email Newsletters Vista UPDATE, Windows IT Pro UPDATE & More

How can i retrieve all Columns name form C# code?

Last post 08-05-2008, 5:01 PM by misterbeefy. 2 replies.
Sort Posts: Previous Next
  •  05-13-2008, 9:31 AM 29663

    How can i retrieve all Columns name form C# code?

    Hi!,

    I am creating a Web Part, In that i have to include all the columns name related to specific List Item. Like this.

      private SPWeb _SPWeb;

     _SPWeb = SPContext.Current.Web;
                for (int i = 0; i < _SPWeb.Lists.Count; i++)
                    cbAllItems.Items.Add(_SPWeb.Lists[i].Title);

    from the above code i am getting the Lists, Like "Task, Calander, Announcement, etc....". But now i want to retrieve all Fields containing in the listed items, Like the "Task" list contained field such as  Title,  Assigned To, Status, Priority, Due Date. All these fields i want to add in a ComboBox (DropDownList).

    Plz. help me to solve this problem.

    Thanks in advance. 

     

     

  •  07-04-2008, 12:56 PM 29819 in reply to 29663

    Re: How can i retrieve all Columns name form C# code?

    You can use SPFieldCollection to iterate through Fields in the List, see the sample code below

     SPFieldCollection collFields = oWebsite.Lists["List_Name"].Fields;

    for (int intIndex = 0; intIndex < collFields.Count; intIndex++)

    {

    string strFieldName = collFields[intIndex].Title;

    }

  •  08-05-2008, 5:01 PM 29930 in reply to 29663

    Re: How can i retrieve all Columns name form C# code?

    It depends on whether you want the values of the fields, the display name of the fields, or the internal name of the fields. By fields, I mean columns, as they are referenced as SPField.

View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Order Your Fundamentals CD Today!Get up to speed quickly and learn how to uncover rich information management and deployment capabilities with this free SharePoint CD. You’ve Deployed SharePoint…Now What?This one-day free online conference delivers the technical knowledge needed to kick MOSS up a notch. In one information-packed day, independent SharePoint experts will present practical, real-world information and provide take-away, ready-to-use solutions Ease Your Scripting Pains with the Flexibility of PowerShell!Join MVP Paul Robichaux on December 11, 2008 at 11:00 AM EDT as he equips you with PowerShell basics in 3 introductory lessons, each followed by a live Q&A session—all on your own computer! Protecting Sharepoint with Double-Take for Windows 5.0Providing SharePoint recoverability is a two step process. Learn those steps now. Vendor protection solutions for SharePoint are incomplete at worst and unreliable at best. So what’s an Administrator to do? Read More… Maximize Your SharePoint Investment This web seminar discusses how true bi-directional replication of SharePoint content from one server to another enables branch offices to maintain access to current SharePoint content.