2

In SharePoint 2013 site. I have many documents library and many folders inside document library.

I'm trying to display all these documents library and folders in console application.

Please suggest something

1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;

namespace ConsoleApplication2
 {
  class Program
{
    static void Main(string[] args)
    {

        using (SPSite oSite = new SPSite("http://pc5"))
        {
            using (SPWeb oWeb = oSite.OpenWeb())
            {
                //Get the collection of all documents library
                SPListCollection docLibraryColl = oWeb.GetListsOfType(SPBaseType.DocumentLibrary);

                foreach (SPList list in docLibraryColl)
                {
                    //Display Document libarry name 

                    Console.Write(list.Title);


                    if (list != null)
                    {
                        foreach (SPListItem item in list.Folders)
                        {
                            //Display Folder from document library
                            Console.WriteLine("Folders from" + list.Title+ "are as follows");
                            Console.WriteLine(item.Title);
                        }
                        Console.ReadLine();
                    }
                }
            }
        }
    }
}
}
8
  • thanks, but am getting error on using SPSite,SPWeb, and SPList wht to do ? – JishinK Dec 5 '16 at 6:58
  • Have you added Reference Microsoft.SharePoint – Akshay Dattatray Nangare Dec 5 '16 at 7:23
  • Yes i added the reference – JishinK Dec 5 '16 at 8:32
  • What is error message ? – Akshay Dattatray Nangare Dec 5 '16 at 12:51
  • a red under line unable to run – JishinK Dec 5 '16 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.