How to check for the sub folder in the document library Is already Exist using CSOM?

Hi,
My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
I able to check for the parent folder.
But cant able to check the subfolder in the document library.
How to check for  the sub folder in the document library?
Here is the code for the folder
IsFolder alredy Exist.
private
string IsFolderExist(string InputFolderName)
string retStatus = false.ToString();
try
ClientContext context =
new ClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
            context.Credentials =
CredentialCache.DefaultCredentials;
List list = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
FieldCollection fields = list.Fields;
CamlQuery camlQueryForItem =
new CamlQuery();
            camlQueryForItem.ViewXml =
string.Format(@"<View  Scope='RecursiveAll'>
<Query>
                                        <Where>
<Eq>
<FieldRef Name='FileDirRef'/>
<Value Type='Text'>{0}</Value>
                                            </Eq>
</Where>
</Query>
                            </View>",
@"/sites/test/hcl/"
+ InputFolderName);
            Microsoft.SharePoint.Client.ListItemCollection listItems = list.GetItems(camlQueryForItem);
            context.Load(listItems);
            context.ExecuteQuery();
if (listItems.Count > 0)
                retStatus =
true.ToString();
else
                retStatus =
false.ToString();
catch (Exception ex)
            retStatus =
"X02";
return retStatus;
thanks
Sundhar 

Hi Sundhar,
According to your description, you might want to check the existence of sub folder in a folder of a library using Client Object Model.
Please take the code demo below for a try, it will check whether there is sub folder in a given folder:
public static void createSubFolder(string siteUrl, string libName, string folderServerRelativeUrl)
ClientContext clientContext = new ClientContext(siteUrl);
List list = clientContext.Web.Lists.GetByTitle(libName);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
@"<View Scope='RecursiveAll'>
<Query>
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>1</Value>
</Eq>
</Where>
</Query>
</View>";
//camlQuery.FolderServerRelativeUrl = "/Lib1/folder1";
camlQuery.FolderServerRelativeUrl = folderServerRelativeUrl;
ListItemCollection items = list.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
Console.WriteLine(items.Count);
if (0 == items.Count)
//create sub folder here
Best regards
Patrick Liang
TechNet Community Support

Similar Messages

  • How can I create a sub-folder within my "Documents" folder?

    How can I create a sub-folder within my "Documents" folder? I have many similar documents that I want to group together. This will also un-clutter my Documents folder.

    Also, you can add a New Folder button to the Finder's toolbar by opening Finder, going to the View menu in the menubar, selecting Customize Toolbar..., and dragging the New Folder icon to the toolbar in the Finder window. Then it's just one-click for new folders wherever you want them.

  • How to move files to Archive folder in same document library

    hi,
    we have one document library (Upload Documents) in that document library we have Archive Folder , when upload document to upload document library first we want check same document   name is there or not and check version also ,if the same document
    is there in that document library then move to that  document to Archive  folder  with  same version and add to document to  upload document library..
    ex:
    Document Lib name:---Upload document
    folder name-->Archive Folder
    Document: Test.txt and version is 1.0
    when upload  same document to document library the Test.txt file move to archive folder and add same document in upload document library with new version

    you can look at Item Adding Event receiver and before you add the new document do you check and move the document to archive folder 
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • When I try to put the downloaded firefox into the application folder, it says a newrer version already exists, do you want to replace it. What should I do.

    I have several older versions of Firefox in my application folder. I downloaded 5.0 and when I went to put it into my application folder a pop up window said a NEWER version already is in the folder - do I want to replace it.
    It doesn't make sense. It won't just accept the new version as it previously did with other versions. I just want to know if I should go ahead and replace version.

    If there are problems with updating or with the permissions then easiest is to download the full version and trash the currently installed version to do a clean install of the new version.
    Download a new copy of the Firefox program and save the DMG file to the desktop
    * Firefox 6.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Trash the current Firefox application to do a clean (re-)install
    * Install the new version that you have downloaded
    Your profile data is stored elsewhere in the Firefox Profile Folder, so you won't lose your bookmarks and other personal data.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox

  • When i double click itunes it doesn't open it just comes up with an error saying " The itunes library.itl file cannot be found or created. The default location for this file is in the 'itunes' folder in the 'music' folder". How can i fix this?

    When i double click itunes it doesn't open it just comes up with an error saying " The itunes library.itl file cannot be found or created. The default location for this file is in the 'itunes' folder in the 'music' folder. How can i fix this problem?

    Anyone can help to advice how to solve this issue ?

  • When I try to open ITunes it brings up a box that says the iTunes Library. itl file cannot be found or created. the default location for this fie is in the itunes folder in the music folder How do I solve this

    My laptop was updating itunes and turned off and every since when i try to load itunes it brings up a window that says
    The itunes library.itl fie cannot be found or created. The default location for this fie is in the itunes folder in the Music folder.
    an I cant figure out what to do to get itunes to load so I can't use itunes at all which ***** since it also means I right now I can't add music to my ipod or apps or anything. So hopefully someone can tell me what happened and how to fix it or solve it

    Hi pgarard1,
    If you are having issues with launching iTunes after an update, you may want to take a look at the troubleshooting in the following article:
    iTunes for Windows: Doesn't open after upgrading in Windows Vista or Windows 7
    http://support.apple.com/kb/TS2363
    Regards,
    - Brenden

  • TS1717 iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder."  How can I fixt this?

    iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder".  How can I fix this?

    Hi pgarard1,
    If you are having issues with launching iTunes after an update, you may want to take a look at the troubleshooting in the following article:
    iTunes for Windows: Doesn't open after upgrading in Windows Vista or Windows 7
    http://support.apple.com/kb/TS2363
    Regards,
    - Brenden

  • How can I open all the tabs saved in a sub folder of the bookmark menu simultaneously in a single click/command ?

    I have saved some of the related tabs in a common sub folder in the bookmarks list and whenever i have to open this tabs always i have to open them individually coz the 'open all in new tabs' option is not available for subfolder, so is there any command or click available from which i can directly open all the saved tabs of a subfolder simultaneously in one single attempt ? using vaio laptop, windows 7 basic, firefox version 6.0.2 !

    yes i do that on my desktop but i dont have middle click option on laptop and even in the right click context the ''open all in tabs'' option is desplayed but is in light color i.e. not functional. Is this a problem with windows 7 or missing plugin or add on could help or extension of some sort ? please help !

  • My MacKeeper says iPhoto is out of date.  When I try to update the App Store says I need IOS 10.9 or later.  I have 10.7.5 and when I check for updates my Mac says the software is up to date.  How do I solve this problem??

    My MacKeeper says iPhoto is out of date.  When I try to update it, the App Store says I need IOS 10.9 or later.  I have 10.7.5 and when I check for updates my Mac says the OS software is up to date.  How do I solve this problem??

    1. First step to solving the Problem: Trash MacKeeper. It's a pile of trash that does far more harm to your computer than good.
    https://discussions.apple.com/docs/DOC-3691
    2. What version of iPhoto do you have? (iPhoto Menu -> About iPhoto)

  • Hi!! how can i read mails present in the sub folder from outlook inbox

    hi every one...
    i have to read a sub folder present in the inbox from outlook.
    for that i tried as
    Session session = Session.getDefaultInstance(props, null);
    store = session.getStore("pop3");
    store.connect("URL", "USERNAME","PASSWORD");
    inbox = store.getFolder("INBOX/subFolderName");but it shows an error like Folder Not Exist...
    can any one suggest me to solve this problem to read mails present in the sub folder.
    Thank you

    thank you for support guys...
    so if i am using pop3 protocal, it cant read the sub folders present in the outlook inbox ..
    is there any alternative way to achieve this ...?

  • TS2972 Since a recent Itunes upgrade I've lost the settings facility in home sharing to import tracks not in my library.  When I check for updates I'm running the latest version.  Any ideas how to resolve this?

    Since a recent Itunes upgrade I've lost the settings facility in home sharing to import tracks not in my library.  When I check for updates I'm running the latest version.  Any ideas how to resolve this?

    Sadly, the iPhone 3G can not be upgraded beyond iOS 4.2.1.

  • Bug with workflow that creates a folder and sub folder with the same name.

    Hi,
    I've found a possible bug in SharePoint 2010 workflows. I only have access to SharePoint 2010 and SharePoint Designer 2010 over my companies intranet, afaik I don't have access to to logs or anything server side so sorry for the any missing information.
    I had some problems with a workflow in one list that needed to create some folders and subfolders in a second list. The production version did a lot more so I setup a test area with 1 list and a workflow that only does the folder creation part and have managed
    to consistently replicate this problem.
    The test list has two columns, [title] and [sub folder title]
    The workflow starts by getting the values for [title] and [sub folder title] into variables.
    It then creates a folder in the same list with the same name as [title], and then creates a sub folder under this with the name from [sub folder title]
    So the resulting structure would be:
    Test List:-
        List item with fields [title] and [sub folder title]
        [folder: title]:-
            [folder: sub folder title]
    If both folder names are different (e.g Folder1 and Folder2) then it works perfectly fine, if both folder names are the same (regardless of character case, e.g. samefolderName and sameFolderName) then the workflow fails.
    As part of the test i made the first action of the workflow to log the message "Workflow Started" to the history list. When the workflow fail there's nothing logged in the history list other than the error: "The workflow could not update the
    item, possibly because one or more columns for the item require a different type of information."
    Creating a sub folder with the same name as it's parent works fine manually but for some reason a workflow can't seem to do it in one action.
    As there's no history list entries before the error it looks like the workflow is just failing to start but if i do something like add an if statement to check if [title] and [sub folder title] are the same, and only create the subfolder when they are not
    then it runs fine doing what it's set to.
    The function of the workflow in our office was for convenience so were just working without it. Just wanted to post to see if anyone else has come across this/could try to replicate or explain this  and see if it's a SharePoint bug or something specific
    to our setup.
    thanks,
    Martin

    not sure about the specifics of your workflow, but if you're querying the list for the folders... keep in mind that a list lookup will only ever bring back ONE item... even if there are several items that meet the filter criteria... example: if i search
    a list for an item assigned to "john doe", there may be 15 tasks that meet the criteria, and it'll only grab one... this is why SP Designer WARNS you when your list lookup may exhibit this behavior.
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • Page not found Error while creating new sub folder in the Sharepoint Document Library

    Hi All,
    I am a site collection administrator when i creating new sub folder under the folder in document library, am getting below error
    "Page not found  The
    page you're looking for doesn't exist."
    please help me, Thanks in advance!!
    Srinivas

    Hi Srinivas,
    Please check ULS log for more useful information when this error occurs.
    Please also check if this issue could be reprodued in other libraries, if not, you can use the new library instead.
    Thanks
    Daniel Yang
    TechNet Community Support

  • How do I install OSX onto a new SSD (in the place of my optical drive) without transferring all data across.  However, with the applications, system and library on the SSD to improve the speed, but keep non essential items (the home folder) on the HDD

    I have a mid 2009 13 inch unibody 2.53GHz MacBook Pro.  I'm finding that it doesn't run as quickly as it used to. 
    A genius in the Apple store suggested that I replace my optical drive with an SSD, however only use the SSD for OSX, applications, system and library.  Keep all documents, pictures, music etc on the current hard drive. 
    I would be grateful if someone could help me with:
    1) installing OSX on the SSD without copying across data from the current hard drive
    2) transferring applications, system and library folders across to the SSD so that they still function
    3) changing my settings so that OSX reads the home folder from the current hard drive, as well as all the applications' data (documents, music etc...)
    However, I would like to run iMovie, with all events etc solely from the SSD to speed up the process of editing movies.
    If anyone could help with this, it would be much appreciated.

    If you got the data transfer cable with your SSD, the procedure should be pretty simple - and there should be step-by-step instructions in the box. You're simply going to remove the bottom case of your computer (using a Phillips #00 screwdriver), take out the two screws in the bracket holding the hard drive into place (using same screwdriver), remove the drive and (use a Torx 6 screwdriver) remove the four screws that hold the hard drive in place. Then put in the SSD and reassemble the machine.
    Then you'll plug up the old hard drive by using the SATA to USB cable and use the option key to boot from the old drive. I don't know what data transfer software Crucial provides, but I would recommend formatting the SSD  using Disk Utility from your old drive ("Mac OS Extended (Journaled)" with a single GUID partition) and then use Carbon Copy Cloner to clone your old drive to your new SSD (see this user tip for cloning - https://discussions.apple.com/docs/DOC-4122). You needn't worry about getting an enclosure since you have the data transfer cable and you don't want to use your old hard drive.
    There are a number of videos on YouTube that take you step-by-step through this procedure - many specific to Crucial SSDs and their data transfer kit - do a little searching there if you're unsure of how to procede.
    Clinton

  • Check for null or empty in the functoid

    I want to check for null and empty values on input source node. If there exists a null or empty in the input source node, I should not pass that to output destination node. Does the
    following attachment work? I want to check for null or empty in the date and time and then concatenate them to send to output. If any of them is null or empty, the other should not fail. In the Not Equal Functoid I am checking for blank, but how to check for
    null?

    A null check might not be you best option.  If your requirement is you must have both the date and time component supplied in order to populate EventDate, then I would use a Script Functoid that takes data and time as parameters.
    In the C# method, first check if either is an empty string, if so return an empty string.
    If not, TryParse the data, if successful, return a valid data string for EventDate.  If not, error or return empty string, whichever satsifies the requirement.

Maybe you are looking for

  • Creation of Service Contract

    Hello Is it possible to create Service Contract through LSMW - BAPI methodology in SAP CRM EHP-2  ?? Can anybody throw some light on : how to achieve it Thanks in Advance. Abhi

  • Best method for keeping iMovie projects long term?

    I read through 30 pages of posts as I think this is a pretty basic question, but didn't see it directly addressed, so please forgive me... Some of my movies are mammoth in size (as much as 30GB for 1 movie), which I've learned are due to iMovie handi

  • How can we add multiple editable region in template

    Hi, My issue is when I am going to create a new template I want to add multiple editable region in template and I want to use those editable region per page wise so that in page editor I will add different text for each page for those editable region

  • Chapter Numbers in FM10

    I just started using FM10 and am having difficulty getting it to automatically input the chapter numbers. Is there a secret to getting FM to do this? Thanks, Leah

  • When clearing a form, is there a way to also clear the photos?

    I have an existing form created using Adobe Pro's form creation. This contains a label tool for adding photos.  When I clear the form, the photos remain. Is there a way to clear out the photos of a form after one has already been linked? Thanks,