By using the following code we can get the views available in the list
// Get the list the list and display the views using the SPViews object. public static void GetListViews() { string siteUrl = string .Empty; string listTitle= string .Empty; SPListCollection listItemCollection; SPList list; Console.WriteLine( "Enter the url of the site" ); try { siteUrl = Console.ReadLine(); if ( string .IsNullOrEmpty(siteUrl)) { Console.WriteLine( "url not be empty or null" ); } else { using (SPSite currentSite = new SPSite(siteUrl)) { using (SPWeb currentWeb = currentSite.OpenWeb()) { if (currentWeb.Exists) { listCollection=currentWeb.Lists; if (listCollection!= null ) { Console.WriteLine( "Enter the Title of the list" ); listTitle=Console.ReadLine(); if ( string .IsNullOrEmpty(listTitle)) { Console.WriteLine( "list title not empty or null" ); } else { if (listCollection[listTitle]!= null ) { foreach (SPView view in listCollection[listTitle].Views) { Console.WriteLine(view.Title); } } else { Console.WriteLine( "current wed not contained list with the title name you entered" ); } } } else { Console.WriteLine( "list collection not exists in the current web" ); } } } } } } catch (Exception e) { Console.WriteLine(e.Message()); } Console.ReadKey(); } |
Hope this will help.
Comments