create folder RRS feed

  • Question

  • Hello everyone,

    I am trying to create folder at this path:

    C:\\User\\James\\. When i am access folder using this code:

     StorageFolder fold = await StorageFolder.GetFolderFromPathAsync(@"C:\\Users\\James");

    Its throw exception of unauthorizes exception. that is access is denied. So how to create folder at this location. Thanks in advance.

    Monday, August 19, 2013 1:02 PM


All replies

  • This is possible because the user for which you are trying to create a folder is not the same user with which application is running.

    And in which folder of this user, i mean what is the exact path where you want to create an folder, is there any specific folder like My Documents("C:\\Users\\James\\My Documents") in which you want to create a new folder or you just want it in the root directory.

    You can use the following command to get the folder path, this will independent of the user with which application will be running, so if the application will be running with the user James it will automatically resolve the path for James


    The above command will automatically resolve the path till "My Documents" present in the "C:\\Users\\James" folder.

    Monday, August 19, 2013 1:38 PM
  • Windows store app do not have access to random folders on hard drive. Check this out for more details on permissions. 

    In your case, it seems that location you are trying to access do not have proper authorization. You will most probably need to use File Pickers to get the required access for this location. 

    Thanks, Sachin

    Monday, August 19, 2013 6:18 PM
  • Hi,Khant

    Just as Sachin says,your app doesn't have access to hard drive , so you cannot create files


    By default windows store apps have access only to their install and application data files. They

    can gain access to libraries via declaration and other files only as granted via the file picker.

    You can use  FolderPicker and PickSingleFolderAsync to pick the folder in the location

    which you want to access .Refer to this linkbelow to see how to use FolderPicker  to pick



    Best Wishes!

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Edited by Anne Jing Tuesday, August 20, 2013 1:35 PM from
    Tuesday, August 20, 2013 1:18 PM
  • Hello anne & Sachin,

    If this is not possible than why we choose file from other drive or other location using fileopenpicker. It is possible because the fileopenpicker is readonly, we cannot write file using fileopenpicker, Is that true?

    • Edited by Khant Nipun Wednesday, August 21, 2013 5:43 AM
    Wednesday, August 21, 2013 4:56 AM
  • Your app has direct access to its install (read only) and application data (read and write) directories. Other directories can be accessed only via the file broker by permission from the user. GetFolderFromPathAsync will return a StorageFolder only for folders the app has direct permission for.

    The FileOpenPicker and FolderPicker are the primary ways for the user to grant permission (capabilities are another), and the app can write files or folders via the StorageFolder returned from the FolderPicker.

    See Skip the path: stick to the StorageFile and Dealing with Documents: How (not) to use the documentsLibrary capability in Windows Store apps


    • Marked as answer by Khant Nipun Wednesday, August 21, 2013 7:41 AM
    Wednesday, August 21, 2013 6:16 AM
  • Hello Rob,

    So this is possible. You can guide me to how to do that without fileopenpicker. My requirement is, create folder into this path: "C:\\Users\\James". Into james folder create one folder temptemp, In temptemp folder create another folder tempfinal. In this folder save some documents file. So what i do?

    Wednesday, August 21, 2013 6:27 AM
  • No, it is not possible.

    Your app does not have access to c:\users unless the user grants permission with the folderpicker. This permission can be saved for later, but the user has to grant it in the first place.

    For temporary files I'd recommend using ApplicationData.TemporaryFolder rather than creating your own.


    Wednesday, August 21, 2013 6:41 AM
  • You can use FileSavePicker if you want to save a file to a folder, but it requires user consent by having them actively pick the file they want to save to. http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.filesavepicker.aspx

    twitter: http://www.twitter.com/dotMorten
    blog: http://www.sharpgis.net

    Wednesday, August 21, 2013 7:09 AM