locked
[UWP]Organising Universal App assets into sub-folders RRS feed

  • Question

  • Hi All,

    I'm writing a universal app and I want to ship a bunch of assets (XML files, images etc).

    I figured out if I mark a file as "content" in Visual Studio, that file get's installed to the App's install folder (Current.InstalledLocation). This is working well, BUT I'm going to be shipping many files, I don't want to just dump hundreds of unorganised files in the install folder. I would like to organise them into folders. I notice the App's icons etc get put in a "Assets" folder. I have tried placing the shortcut to my file in the Project's "Assets" filter, but that seems to make no difference, the file still gets dumped in the main install folder.

    How can I specify a particular sub-folder for an asset. e.g. "InstalledLocation"/MyFiles/MyFile.xml ? How is it the App icons get their own folder?

    Any help appreciated,

    Jeff


    • Edited by Barry Wang Tuesday, April 5, 2016 9:40 AM title tags
    Friday, April 1, 2016 12:38 AM

Answers

  • Hello Jeff Mc,

    >>but I want to install them in a sub-folder. In the same way that "Assets" is a sub-folder beneath the application install folder.

    >> I suspect I must copy the source files into a subfolder of the Visual Studio project folder (the same way "Assets" are).

    Yes that's right. If you still want your source files in the installed location then you will need to create a new folder like Assets folder. When you deploy your app the new folder will also be deployed. You can test the location at runtime to see the result.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Barry Wang Wednesday, April 13, 2016 5:35 AM
    • Marked as answer by Barry Wang Thursday, April 14, 2016 8:11 AM
    Thursday, April 7, 2016 8:04 AM

All replies

  • Hello Jeff,

    The App icos is defined in Package.appxmanifest so we have to put them in the installed Assets folder:

    But if you want to put files in some other folder instead of installed folder, then you can refer to this article:

    File access permissions

    You will find that you can use ApplicationData.LocalFolder or some other folders to put your files.

    To read them you can use the URI like using the following code:

    using Windows.Storage;
    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync("ms-appdata:///local/file.txt");

    For details please check the following article:

    Files, folders, and libraries

    By the way, to read subfolders, use StorageFolder.GetFolderAsync then loop to use StorageFolder.GetFolderAsync  again. 

    For example, read installed folder then use above class to read subfolder.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Barry Wang Tuesday, April 5, 2016 9:43 AM
    Tuesday, April 5, 2016 9:38 AM
  • Barry, Appreciate your help.

    I do want files in my application folder, not another folder, but I want to install them in a sub-folder. In the same way that "Assets" is a sub-folder beneath the application install folder. I know how to access the files at runtime, that part is working fine. I don't know how to specify any install location for project "content" items other than  the root application install folder. I suspect I must copy the source files into a subfolder of the Visual Studio project folder (the same way "Assets" are).
    Wednesday, April 6, 2016 8:44 AM
  • Hello Jeff Mc,

    >>but I want to install them in a sub-folder. In the same way that "Assets" is a sub-folder beneath the application install folder.

    >> I suspect I must copy the source files into a subfolder of the Visual Studio project folder (the same way "Assets" are).

    Yes that's right. If you still want your source files in the installed location then you will need to create a new folder like Assets folder. When you deploy your app the new folder will also be deployed. You can test the location at runtime to see the result.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Barry Wang Wednesday, April 13, 2016 5:35 AM
    • Marked as answer by Barry Wang Thursday, April 14, 2016 8:11 AM
    Thursday, April 7, 2016 8:04 AM