Hi there
Below source from console app is printing SPList Columns Internal name as well as the Data for the SPFields.
But it appears to be incorrect. Like to print Column name, then data for that column.
Example:
Title : SharePoint 2010
StartDate: 12/03/2013
I think that it is feasible without SPQuery or SPView, without hard coding column names to get the data.
Help in refactoring below source with better approach is greatly appreciated.
static void SharePointData() { using (SPSite site = new SPSite("http://intranet.contoso.com")) { using (SPWeb web = site.RootWeb) { SPList list = web.Lists["Tasks"]; if (list != null) { SPFieldCollection fields = list.Fields; SPListItemCollection items = list.Items; Console.WriteLine("Printing Column names"); Console.WriteLine("@@@@@@@@@@@@@@@@@@"); foreach (SPField field in fields) { Console.WriteLine(field.InternalName); } Console.WriteLine("##################"); Console.WriteLine("Printing Columns Data"); foreach (SPItem item in items) { foreach (SPField field in item.Fields) { Console.BackgroundColor = ConsoleColor.Blue; Console.WriteLine(item[field.InternalName]); } } } Console.ReadKey(); } //Console.Read(); } }