Below Code block explains how to Get the Names of all fields in a SharePoint list Programmatically.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.SharePoint;
-
- namespace SharePoint
- {
- class ListFields
- {
- static void Main()
- {
- SPSecurity.RunWithElevatedPrivileges(delegate()
- {
- string siteUrl = "http://abhay-pc:1212";
- SPSite site = new SPSite(siteUrl);
- Console.WriteLine(site.ToString() + "\n");
- SPWeb web = site.OpenWeb();
- SPList list = web.Lists["EmployeeDetails"];
- Console.WriteLine(list.ToString() + "\n");
- foreach (SPField f in list.Fields)
- {
- Console.WriteLine(f.StaticName.ToString() + " - " + f.TypeDisplayName.ToString() + "\n");
- }
- });
- Console.ReadLine();
-
- }
- }
- }