How to get all list names in a specified SharePoint site ?

Suppose you are working on a SharePoint site and you want to get the name of all list used in this particular SharePoint site. So, this code snippets will give you all the list name from a SharePoint site.

To get the name of all list from a SharePoint site you need to write few lines of code.

Please follow below steps to complete this task.

Step1. Open visual studio.
Step2. Create a new Console Application project.
Step3. Paste the below code in your .cs file.

class Program {
static void Main(string[] args) {
// Update to your server name
using (SPSite siteCollection = new SPSite("http://sharepointsite:1657")) {
SPWebCollection site = siteCollection.AllWebs; foreach (SPWeb web in site) {
try {
SPListCollection lists = web.Lists; Console.WriteLine("Site: {0} Lists: {1}", web.Name, lists.Count.ToString());
foreach (SPList list in lists) {
Console.WriteLine("List: {0}", list.Title); } } //
catch (Exception) {
throw; }
finally {
web.Dispose(); } }
} // dispose is called on site as a result of using()
Console.WriteLine("Please press 'enter'to continue");
Console.ReadLine(); } }

Note:One thing you need to change is url of SharePoint site.
Now run your program by pressing F5, you will see all the list name of the SharePoint site that you have mentioned in this code.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: