locked
Package.Current.InstalledLocation.GetFolderAsync can't get the new folder under Assets RRS feed

  • Question

  • I'm building a Windows 8 app. This app has an item page with a list of files, and when one of these files is selected, the app should open that file.

    With these analysis I started to produce code but immediately I was confronted with the difficulty to open a directory that contains a list of files in windows 8 app. In particular I created a directory under Assetswith name Report that contains the files list (pdf, txt, any kind of files). When I need to open this directory programmatically, I'am not able to open it because I get this exception: 

    System.IO.FileNotFoundException

    but the directory exists in the solution folder. I try to open it with:

    var folder = await StorageFolder.GetFolderFromPathAsync(Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Assets\reports");

    but I have fix nothing because I get the exception above.

    In another attempt, I tried to access at that directory using that code:

    IReadOnlyList<StorageFolder> documentsFolder = await Windows.ApplicationData.Package.Current.InstalledLocation.GetFoldersAsync();
    
    foreach(StorageFolder folder in documentFolder){
     IReadOnlyList<IStorageItem> subItems = await folder.GetItemsAsync();
    
     foreach (IStorageItem subFolder in subItems)
     {
         try
         {
            ...                
         }
         catch(FileNotFoundException e1) { 
            ...
         }
    }

    In this second approach, I tried to get the Assets folder (with the first loop), and I got it, and the report folder (with the second loop), that I'm not able to get it because the directory named reports does not exists.

    Please, anyone of you know C# and windows 8 app better than me, please help me.

    I look forward to hearing from you.

    Thank you for time you reserved to me.

    Wednesday, November 20, 2013 8:47 AM

Answers

  • Make sure your files are marked as content and to be copied to the output directory. Otherwise they won't be placed in the appxpackage and available at runtime.

    --Rob

    Wednesday, November 20, 2013 4:30 PM
    Moderator
  • look at the properties of the file and then at build action. In the solution explorer select the file and press F4. The property pane will show up and there you can select the build action

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Proposed as answer by Sachin S Wednesday, November 20, 2013 7:41 PM
    • Marked as answer by Paride Letizia Thursday, November 21, 2013 11:16 AM
    Wednesday, November 20, 2013 6:14 PM

All replies

  • Hi Paride,

    It works fine on my side, if we have nothing in the reports folder, your first code will throw "System.IO.FileNotFoundException", but if we have at least one file in the folder, the code should be ok. The reason is while building the app, the empty folders will be ignored.

    I guess in your situation, there is no file in the reports folder while deploy the app. Let's say you could monitor your InstalledLocation to see if the folder exists or not, if the folder exist but your app throw an exception, we need dig in to it.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    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.



    Wednesday, November 20, 2013 9:38 AM
    Moderator
  • Hi James,

    first of all thank you for reply. The folder reports is not empty but contains some pdf files. I already thought that the problem could be the empty folder, but it is not.

    When I access in InstalledLocation, I can see just Assets and Commons directories and into Assets ther isn't any reports folder. I'am getting crazy to solve this problem

    Thank you in advance

    Wednesday, November 20, 2013 12:59 PM
  • Make sure your files are marked as content and to be copied to the output directory. Otherwise they won't be placed in the appxpackage and available at runtime.

    --Rob

    Wednesday, November 20, 2013 4:30 PM
    Moderator
  • Thanks Rob.

    I just putted those files in the report directory under assets. I do not understand how to marked them as content and how to copy them to the output directory.

    Could you explain me how to do these operations?

    Thank you very much

    Wednesday, November 20, 2013 5:04 PM
  • look at the properties of the file and then at build action. In the solution explorer select the file and press F4. The property pane will show up and there you can select the build action

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Proposed as answer by Sachin S Wednesday, November 20, 2013 7:41 PM
    • Marked as answer by Paride Letizia Thursday, November 21, 2013 11:16 AM
    Wednesday, November 20, 2013 6:14 PM
  • Hi, 

    could you clarify a doubt? If I have a filder with a list of pdf files, is it normal that for windows this folder is empty?

    I tell you that because I am able to see just a txt files list, if I put in that folder some pdf files, windows tells me the folder is empty. I do not why.  

    Thanks in advance.

    Bye 

    Monday, December 23, 2013 10:21 AM
  • Hi Parade,

    Please mark the PDF files as content as described in this thread. PDF files do not default as content, but text files do (usually: it may depend on how they are added).

    --Rob

    Monday, December 23, 2013 4:04 PM
    Moderator