locked
How to reference a folder and create a file inside the App

    Question

  • I am confused with Installed Folder and LocalFolder using below to reference:

    a) Windows.ApplicationModel.Package.Current.InstalledLocation
    b) ApplicationData.Current.LocalFolder

    The problems:

    1) What are the differences ? what is installed folder?

    2) If I have a folder called MyFile in my App Just like the predefined folder called Asset, Which one do I use (a) or (b) to reference it or how do I reference the Asset folder inside my App ?

    3) If I wanted to create a Folder, where do I create it (a) or (b) ? What are the advantages?

    4) How do I create a file (say , Nature.jpg)  in the "Myfile" folder in (2)  and write the image stream or bytes in it?

    Your help is greatly appreciated.

    Tuesday, March 4, 2014 2:49 PM

Answers

  • You can dump the LocalFolder's Path with:

    Debug.WriteLine(ApplicationData.Current.LocalFolder.Path);

    Once you know the path open a command prompt and cd to that directory:

    Microsoft Windows [Version 6.3.9600]
    (c) 2013 Microsoft Corporation. All rights reserved.
    
    C:\Users\rob>cd C:\Users\rob\AppData\Local\Packages\44c9deab-bf84-4a48-b16f-8c900d62c97b_edj12ye0wwgwa\LocalState
    
    --Rob

    • Marked as answer by FireDance Monday, March 10, 2014 1:49 PM
    Thursday, March 6, 2014 6:50 PM
    Owner

All replies

  • InstalledLocation is the folder the app is installed in. This is read only and contains the app binaries and content included in the app package when the app is built.

    LocalFolder is for local application data. This is writeable and per user. See Managing app data

    To save your image data you'll use the LocalFolder. You already have another thread discussing how to do so, so lets not confuse things by discussing it in multiple places.

    --Rob

    • Proposed as answer by Dave SmitsMVP Tuesday, March 4, 2014 8:59 PM
    Tuesday, March 4, 2014 3:24 PM
    Owner
  • Understand my previous thread contains quite a number of tasks and I want to understand clearly how Storage and  App works in it. This will help to avoid confusing myself.

    InstalledLocation is the folder the app is installed in.

    Since I have added a folder inside the app project, can I add files in it after it is built? I need to access webservice to get data which need to store in that folder. If I store data from webservice in that folder, will the files be visible just like as if I add images files in it manually.

     

    Thanks

    Wednesday, March 5, 2014 1:09 AM
  • No, you cannot write to the app's installed location or package at runtime (once it's installed: you may be able to during development since you're running out of a local stage). The app will install into Program Files and not have write access there.

    For run-time data you'll create and save your folder in the app data directories (such as LocalFolder). See the docs I linked for details. You can access files in app data with the ms-appdata protocol rather than the ms-appx protocol used for the packaged files.

    --rob

    Wednesday, March 5, 2014 1:45 AM
    Owner
  • a) Thank u so much for the Explanation. Just to reconfirm my understanding:

    1) No Write access (write file ) in Folders inside App project which in InstalledLocation

    2) have read access for files in (1)

    3) Can not Create Folders inside App project which in InstalledLocation

    b) For LocalFolder

    1) How can I check or view the files which I created or Write data to inside the LocalFolder ? Just to see visually without using code to check if it is created or empty and so forth.

    Thanks

    Wednesday, March 5, 2014 2:09 AM
  • Correct. Your app can read but cannot write from its InstalledLocation.

    The app can both read and write in its app data locations.

    To view the local folders examine the LocalFolder StorageFolder in the debugger to get its path and then you can look at the contents in Explorer or a command prompt.

    --Rob

    Wednesday, March 5, 2014 6:36 AM
    Owner
  • Hi,

    I had set many break points to follow thru as well as step thru all the codes that consuming the WebServices. I did verify there were Base64 data being sent over.  But I need your help to show me how to use your methods to view the LocalFolder if I did successfully save one.  Appreciate your help to show me the steps or screenshot of where to click and not sure how to use the command prompt.

    Thanks

    Thursday, March 6, 2014 2:15 PM
  • You can dump the LocalFolder's Path with:

    Debug.WriteLine(ApplicationData.Current.LocalFolder.Path);

    Once you know the path open a command prompt and cd to that directory:

    Microsoft Windows [Version 6.3.9600]
    (c) 2013 Microsoft Corporation. All rights reserved.
    
    C:\Users\rob>cd C:\Users\rob\AppData\Local\Packages\44c9deab-bf84-4a48-b16f-8c900d62c97b_edj12ye0wwgwa\LocalState
    
    --Rob

    • Marked as answer by FireDance Monday, March 10, 2014 1:49 PM
    Thursday, March 6, 2014 6:50 PM
    Owner
  • Thanks. I managed to find the LocalState. Whatever is stored there will not be erased after testing with emulator?

    This issue is clear now. I will revisit my previous link.

    Monday, March 10, 2014 1:51 PM