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

Maximize Your SharePoint Investment: Get Your Data MovingJoin us as we take a look at the complex business of securing, accessing and managing vast amounts of information in a global network and various ways to get your data moving. 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. Free Technology Resource Directory ListingPost your free listing in this comprehensive directory for IT and developer professionals, powered by Windows IT Pro. But hurry! Deadline ends Oct. 9. SharePoint Connections event returns to Las Vegas Nov 10 - 13Connections returns to Las Vegas for this exciting event where each attendee will receive SQL Server 2008 standard with 1 CAL. It is co-located with Microsoft ASP.NET, SQL Server and Windows Connections with over 250 in-depth sessions. 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!