Check Folder Exist inside SharePoint Document Library Programmatically

Check Folder Exist inside SharePoint Document Library using CSOM Programmatically

Check Folder Exist inside SharePoint Document Library Programmatically. In this post, I described you to Check Folder Exist inside SharePoint Document Library using CSOM Programmatically. If you need to create document library programmatically follow my post Create and Delete SharePoint List, Document Library Programmatically using CSOM.

[AdSense-A]

 public static int GetFolderCS(ClientContext clientContext, String listTitle, String folderName)
        {
            int existingFolder = 0;

            Web web = clientContext.Web;
            ListCollection lists = web.Lists;

            List list = web.Lists.GetByTitle(listTitle);

            if (list != null)
            {
                FolderCollection folders = list.RootFolder.Folders;
                clientContext.Load(folders, fl => fl.Include(ct => ct.Name).Where(ct => ct.Name == folderName));
                clientContext.ExecuteQuery();
                existingFolder = folders.Count();
            }

            return existingFolder;
        }

 

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!