Getting parent folder of file when launching app from an associated file is not possible? RRS feed

  • Question

  • I have an app that needs to read data from two files:

    - main .wet file, and second data file .dry, they are in the same folder

    I associated the .wet extension to the app but it seems like I have no permission to the folder (by calling StorageFile->GetParentAsync() which return null) to retrieve the .dry file when I launch the app from the .wet file? This means I have no way of reading the .dry file thus I can't support file association? Are there any workarounds or am I missing something here because it just seems like a really inconvenient restriction.

    Thanks any wisdom will be appreciated.

    • Edited by Wetdry Thursday, January 22, 2015 9:40 AM
    Thursday, January 22, 2015 9:38 AM

All replies

  • You can't just go poking into any folder, even if it's the folder that caused app activation.  You can use a file picker (which makes sense anyway) to get the file from the same folder.

    Thinking further through this scenario, if the .wet and .dry files are that closely linked, why don't you combine them into a single file so that the app can use the data without any further interaction?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, January 22, 2015 7:17 PM
  • thanks Matt

    I have a desktop app that generate these files. This is basically an Windows runtime app port. The app internally has a custom file browser that uses a folder picker which works as expected when reading both .wet and .dry files. I wanted to add the file association to let my customers be able launch app from double clicking the .wet file but it seems like it is technically not possible. Also combining the files is also not really viable they were separated for a good reason. I would rather just drop the feature of launching the app from file.

    It's just seems like a very poor design decision for the file permissions because you if you internally use a folder picker for example, you have access to all subfolders and subfiles simply having picked one folder. Which is essentially allowing you "go poking into any folder" provided you pick something. But activating an app from a single file does not allow parent folder access.

    For example another use case: I believe Word docs have hidden autosave files in the same directory as the source file. So if there was an unexpected termination you can recover your docs. But in this case it is basically impossible to use this feature if you launch the app from file via explorer.

    Thursday, January 22, 2015 10:45 PM
  • You don't have access to the parent, but you can get the neighboring files from the FileActivatedEventArgs.NeighboringFilesQuery passed when the app is activated via file launch.

    Thursday, January 22, 2015 11:19 PM
  • Rob, I was sooo hoping this would work. I just tested and NeighboringFilesQuery does not support file types outside the default library types (videos, music, pictures etc), as specified in the specs. I even tried to access the Folder pointer and setting different queryOptions. They are all restricted.

    I dont think this is possible. I'll drop the file association feature for now.

    Friday, January 23, 2015 1:14 AM