locked
App Data Subfolders | C++ Metro App

    Question

  • Hello,

    So, I am trying to create a subfolders in the App Data folder because the data that my app uses has multiple subfolders within it, ie:

    AppData\Strings

    AppData\Sounds

    So, in VS 11 I include one of my data files in the Resources folder (ie. text_en.strings which is my English localized strings for the project) but there is no way for me to tell VS to create a subfolder called Strings and put the .strings file in there. It simply puts the file in the root of the AppData folder. 

    Is there a way to change this?

    More generally, is there a way to add any Resource to the project and create subfolders wherever I like the AppData folder to put those resource files?

    Thanks!

    Thursday, May 3, 2012 3:14 PM

Answers

All replies

  • Hello,

    Is your application based on metro? If your application based on Win32, I will help you to move this thread to General C++ forum. This forum is only talking about the metro style application development.

    In Metro we can use ApplicationData.LocalFolder property to get the same function with AppData folder. You can call CreateFolderAsync(String) to create the sub folder.

    ApplicationData.LocalFolder | localFolder property
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localfolder.aspx
    StorageFolder.CreateFolderAsync(String) | createFolderAsync(String) method
    http://msdn.microsoft.com/en-us/library/windows/apps/br227258.aspx

    Here is the sample code about File access sample
    http://code.msdn.microsoft.com/windowsapps/File-access-sample-d723e597/sourcecode?fileId=44740&pathId=1778109266

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by TheMCP Wednesday, May 23, 2012 4:46 PM
    Friday, May 4, 2012 6:14 AM
  • Thanks Jesse,

    Yes, this is for Metro. Thanks for your input!

    Actually, I dont think I explained this well. This is more of a setup question and not a runtime file access question. I am building a metro app that already has a data folder with multiple subfolders in it. When I add one of these data files, say image.png to VS 11 and change its property->Content flag to Yes the data file is properly included in the debug ApplicationData folder which (I think is):

    C:\Users\me\Projects\ProjectX\Source\_Win8\Debug\ProjectX\AppX

    However, VS 11 doesnt maintain the original folder structure from the original location of the data file. I would like to be able to do that. So, here is where the original data file is located:

    C:\Users\me\Projects\ProjectX\data\ds

    So is there a way for me to tell VS 11 to maintain the original dir structure or create a dir structure that will be placed into ...\Debug\ProjectX\AppX?

    This is important to me as a I have multiple subfolders within the \data dir that contain files with identical names:

    \data\ds\image.png

    \data\ds2\image.png

    etc...

    Thanks Again!

    Friday, May 4, 2012 3:04 PM
  • Hi sorry for the long thread. I think I have been barking up the wrong tree with the AppFolder. I think since I am concerned with where to store the immutable data files for my app (ie. the GUI graphics, sound fx, etc) that I should be looking at the Windows::ApplicationModel::Package class instead. I think the code snippet below gets me what I want in terms of where to fetch those files:

    Windows::ApplicationModel::Package^ package; Windows::Storage::StorageFolder^ installedLocation; char Path[1024]; package = Windows::ApplicationModel::Package::Current; installedLocation = package->InstalledLocation; wtoc(Path, (short *)installedLocation->Path->Data());

    Does this seem the correct package to use for accessing the app's immutable data files?

    If that's the case then I can do a pre-build commandline to copy the /data folder and all its subfolders to the "installedLocation->Path" every time I compile/run the program in VS 11.

    Thanks Again




    • Edited by TheMCP Friday, May 4, 2012 9:03 PM
    Friday, May 4, 2012 8:58 PM
  • was there any resolution to this?

    i'm trying to do something similar, but not with image files. i have some binary files i want to statically include (have added to the installed directory) during deployment. when i add them to the project, i select "Excluded from Build = No", "Content = Yes", "Item Type = (tried Image, Media, Object, Resource)" and the file is not installed in the installed directory. So I have to add a post build command line to copy my files to the $(Configuration)\$(ProjectName)\Appx folder. Is that the recommended approach?

    the files are copied there, but i am unable to read them. How do I solve this?

    - CreateFile2 results in error 4252 ERROR_NOT_SUPPORTED_IN_APPCONTAINER

    - below code using winrt APIs also fails (never gets into the getFileOperation.then):

    Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
    Windows::Storage::StorageFolder^ installedLocation = package->InstalledLocation;
    concurrency::task<StorageFile^> getFileOperation(installedLocation->CreateFileAsync(L"test.txt"));
       getFileOperation.then([this](StorageFile^ file)
       {
    	   Platform::String^ fileNames = "";
     		
    	   fileNames = file->DisplayName;
    	   return FileIO::ReadTextAsync(file);
       
       });

    Thanks.

    Thursday, July 12, 2012 7:19 PM