Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Get SPList Items Column Titles and Column Data including the SPLookupFieldValue

$
0
0

Hi there

Below source printing only the List Items that are on the first page of the SPList. Not printing the ListItems data in other pages i.e., Page 2, Page 3 etc.

Also it is required to print SPLookupFieldValue, rather than suggesting some links any modifications to the below source

that can meet the requirement is greatly appereciated.

static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://intranet.contoso.com"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    // Get data from a list. 
                    SPList list = web.Lists["Products"];
                    SPView view = list.DefaultView;
                    SPListItemCollection items = list.GetItems(view);
                    // Get a collection of view field names. 
                    StringCollection viewFields = view.ViewFields.ToStringCollection();
                    // Print data for each item in the view. 
                    foreach (SPListItem item in items)
                    {
                        // Print the value of each view field. 
                        foreach (string fieldName in viewFields)
                        {
                            Console.WriteLine("{0} = {1}", fieldName, item[fieldName]);
                        }
                        Console.WriteLine();
                    }
                }
            }
            Console.ReadLine();
        }

Country Column is Lookup, so the data is printed with ID and value. Needs to print only the value.

Product = Television
Country  = 2;#uk  

Product = Car
Country = 1;#india




Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>