locked
Access to files in package installation folder subfolders

    Question

  • Hello. I am trying to compile an application which stores some *.txt files in application installed location subfolders using next code:

    String^ fileName = L"file.txt";
    StorageFolder^ appInstalledLocation = Windows::ApplicationModel::Package::Current->InstalledLocation;
    String^ relPathToModelsFolder = L"\\Media\\Models";
    task<StorageFolder^ > getFolderWithModels(appInstalledLocation->GetFolderAsync(relPathToModelsFolder) );
    getFolderWithModels.then([fileName] (StorageFolder^ folderWithModels) {
    	return folderWithModels->GetFileAsync(fileName);
    } ).then([] (StorageFile^ modelFile) {
    	return FileIO::ReadTextAsync(modelFile);
    } ).then([this] (String^ readedText)
    {
    	this->str = readedText;
    } );

    The file text.txt exists in folder Media/Models during application deployment and has UTF-8 encoding. However, I get exception "An invalid parameter was passed to a function that considers invalid parameters fatal" at line "return FileIO::ReadTextAsync(modelFile);". But when I try to access to the same file located in app install folder using the next code

    String^ fileName = L"file.txt";
    StorageFolder^ appInstalledLocation = Windows::ApplicationModel::Package::Current->InstalledLocation; 
    task<StorageFile^ > getSubFile(appInstalledLocation->GetFileAsync(fileName) );
    getSubFile.then([] (StorageFile^ subFile) 
    {
    	return FileIO::ReadTextAsync(subFile);
    } ).then([this] (String^ readed)
    {
    	this->str = readed;
    } );

    everything goes fine. Does this mean that we can`t access files in application subfolders? Running Windows 8 RP and Visual Studio 2012 RC.

    Thanks!


    Thursday, July 26, 2012 3:49 PM

Answers

  • Access to subfolders is allowed, but relative paths are not.  Try building the full path to the subfolder first and using that in your GetFolderAsync call.
    • Marked as answer by RenGate Thursday, July 26, 2012 5:09 PM
    Thursday, July 26, 2012 4:30 PM

All replies

  • Access to subfolders is allowed, but relative paths are not.  Try building the full path to the subfolder first and using that in your GetFolderAsync call.
    • Marked as answer by RenGate Thursday, July 26, 2012 5:09 PM
    Thursday, July 26, 2012 4:30 PM
  • Thank you. Usage of full path did the job ;)
    Thursday, July 26, 2012 5:09 PM