private static int GetFolderExists(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); }
/// <summary> /// This function tests for the existance of a subfolder in the designated folder in SharePoint. /// </summary> /// <param name="tmpFolderName"></param> /// <param name="tmpRelPath"></param> /// <returns></returns> public Boolean FolderExists(string tmpFolderName, string tmpRelPath) { Boolean tmpRetVal = false; ClientContext ctx = null; Web tmpWeb = null; List tmpList = null; ListCollection tmpLists; FolderCollection tmpFolders = null; try { ctx = new ClientContext(SPSiteURL); tmpWeb = ctx.Web; tmpLists = tmpWeb.Lists; tmpList = tmpLists.GetByTitle(SPRootPath); if (tmpList != null) { tmpFolders = tmpWeb.GetFolderByServerRelativeUrl(tmpRelPath).Folders; ctx.Load(tmpFolders, fl => fl.Include(ct => ct.Name).Where(ct => ct.Name == tmpFolderName)); ctx.ExecuteQuery(); if (tmpFolders.Count() > 0) { tmpRetVal = true; } } } catch (Exception ex) { tmpRetVal = false; RetErrMessage = ex.Message; } return(tmpRetVal); }