5

I need to access a subfolder in the application folder whose path is:

C:\Users\myname\Documents\Visual Studio 2015\Projects\App2\App2\Templates

and retrieves all the data inside. I need to read the xml files in a subfolder of it, parse them, and store them in a dictionary. I have the parsers ready but just don't know how I can access the folder?

I tried

StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder templateFolder = await localFolder.GetFolderAsync("Templates");

But it didn't work. An error occurred indicating that folder "Templates" could not be found. However, when I tried "Assets" instead, which had been in the folder ever since the project was created, it worked. How can I access it?

Tianshu Chu
  • 143
  • 2
  • 8
  • InstalledLocation is *read-only* - you cannot create files/folders there. If you want to save some data inside the app, then use *LocalFolder*. – Romasz Jun 15 '16 at 06:22
  • Thanks. But what if I just need to read all the StorageFiles in a certain folder? – Tianshu Chu Jun 15 '16 at 06:25
  • It depends on folder. Are you trying to access files that are delivered with your app (content) or create/download files later on? – Romasz Jun 15 '16 at 06:27
  • If you want to know it, you should post another question about reading all files in certain folder)) – Alexej Sommer Jun 15 '16 at 06:27
  • http://stackoverflow.com/questions/21225959/how-to-enable-documentslibrary-capability-in-a-windows-store-winrt-app – Hans Passant Jun 15 '16 at 06:28
  • @Romasz I am needing to access the files in a subfolder. – Tianshu Chu Jun 15 '16 at 06:33
  • Is this subfolder provided with your app (is it set as content)? Also - do you have any file in that folder that is set to *Content*? – Romasz Jun 15 '16 at 06:41
  • Is it in your project? – Hamed Jun 15 '16 at 06:52
  • 1
    Describe "it didn't work". Because the code looks sort of OK. I think @Romasz means: are the files actually there? – H H Jun 15 '16 at 08:13
  • @HenkHolterman I just editted the question! Yes the folder is there. What I was trying to do is first access the templates folder and then access the files. But the folder appears to be invisible from the codes. – Tianshu Chu Jun 15 '16 at 15:46
  • I solved it... I just didn't have the folder in my Solution Explorer. I fixed it. – Tianshu Chu Jun 16 '16 at 05:52

1 Answers1

4

If Template folder is in your project, then you can get it via:

var TempFile = "ms-appx:///Templates/Yourfile.jpg";
Hamed
  • 590
  • 5
  • 16
  • 3
    The answer you have provided is just a string. If you mean to access a file by application uri, then yes - it's possible, but it should also work with InstalledLocation. It also seems that OP wants to parse the folder rather than to get a single file. – Romasz Jun 15 '16 at 07:26