locked
[C#][UWP] How to maintain the default storage folder for an application RRS feed

  • Question

  • Hi All,

    I am creating an app, in which, I need to download some files from the server and I want to download the file on to some user selected folder, For that, I am using FolderPicker.

    But, I want to maintain this selected folder as the default folder for downloading all files. How to do that.

    Regards

    Thursday, July 6, 2017 6:59 PM

Answers

  • Hi,

    I want when the next time user download stuff, the saved folder will be directly used without invoking FolderPicker? 

    Regards

    Hi Prashant,

    Please use the the token + FutureAccessList way in the document. Serialize the storage folder is not going to take you anywhere because UWP won't allow you to access all folders for the sake of security.

    On the other hand, UWP allows apps to access folders that picked by user, which matches your scenario and the document contains examples of how to do it.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Monday, July 10, 2017 4:16 PM

All replies

  • Once the user selects the download folder save the path to the application settings. Refer to this setting the next time a download is executed.
    Thursday, July 6, 2017 7:27 PM
  • Hi!

    You have the same topic with answer in this link : https://social.msdn.microsoft.com/Forums/en-US/e13d0ba0-8450-4304-95be-c83b877545a5/cuwp-how-to-maintain-the-default-storage-folder-for-an-application?forum=wpdevelop

    Hope it wil be useful.

    Please remember to mark the replies as answers if they help, this will help others who are looking for solutions to the same or similar problem

    Follow me on twitter : https://twitter.com/NordineMhoumadi


    Download my NEW FREE application MCP PREPARATION in the Windows 10 Store for preparing your Microsoft Certification or test your skills in Microsoft Technologies;

    Thursday, July 6, 2017 8:48 PM
  • Hi there,

    Check if this is what you are looking for:

    https://docs.microsoft.com/en-us/windows/uwp/files/how-to-track-recently-used-files-and-folders

    Token can be saved using the application settings:

    https://docs.microsoft.com/en-us/windows/uwp/app-settings/store-and-retrieve-app-data


    Thursday, July 6, 2017 8:59 PM
  • Hi,

    Thank you all for your replies. But, it really does not solves my problem. My issue is that, I get an object of StorageFolder whenever a user selects the default download location. And at that time I serialize this object into JSON string and store it into the application's localsettings and when my app initializes then I want to retrieve the same default folder location and set this location and application's localfolder.

    How to do that?

    Regards

    Friday, July 7, 2017 7:40 PM
  • Hi Prashant,

    Could you please explain your question a bit more to help us understand it better:

    What are you plan to do after you fetched the saved location? Is it:

    a. when the next time user invoke FolderPicker, the default folder will be the saved folder? or

    b. when the next time user download stuff, the saved folder will be directly used without invoking FolderPicker? or

    c. Could you please explain the expected behavior have you fetched the saved location?

    Suggestions will be different depends on what you are going to do with the folder. However, unfortunately, serialize the folder object basically is not the right direction. Security is a big consideration here for accessing file systems through UWP.

    ========

    Guessing based on the information you post here, there's a suggestion:

    Please refer the future access list example here to see how to get a token for the folder and then consider save the token instead of the serialized json object: https://docs.microsoft.com/en-us/uwp/api/windows.storage.accesscache.storageitemaccesslist.

    When the time to restore the folder object, get the token back (similar to how you get the serialized folder object), call GetFolderAsync(token) on the FutureAccessList (same result as you serialize your json to folder object).

    ========

    Friday, July 7, 2017 11:11 PM
  • Hi,

    I want when the next time user download stuff, the saved folder will be directly used without invoking FolderPicker? 

    Regards

    Monday, July 10, 2017 10:46 AM
  • Hi,

    I want when the next time user download stuff, the saved folder will be directly used without invoking FolderPicker? 

    Regards

    Hi Prashant,

    Please use the the token + FutureAccessList way in the document. Serialize the storage folder is not going to take you anywhere because UWP won't allow you to access all folders for the sake of security.

    On the other hand, UWP allows apps to access folders that picked by user, which matches your scenario and the document contains examples of how to do it.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Monday, July 10, 2017 4:16 PM
  • Hi,

    Thanks for your answer. It works perfectly.

    Regards

    Monday, July 10, 2017 8:41 PM