Opening Files with WinRT Components RRS feed

  • Question

  • I am working code sample and the simple part of it was to be able to use the file picker to open a file in JavaScript and send it to a C# WinRT component where I'll process the file and actually have the main code sample I want to do. The issue is I'm not sure of how to best to go about the getting my file to the C# component. I have tried the following:

    • Use open file picker in JS to choose file, passed file path to component and tried opening file with StorageFile.GetFileFromPathAsync. This results in an access denied error.
    • Tried using the file picker in c#. This threw an "unspecified error". I wasn't really expecting this to work anyways.
    • I tried passing a file stream but components do not allow streams to be passed through methods.

    Also the file extensions/type may be any available type so I don't want to limit it. Any ideas on how to do this?


    Tuesday, October 15, 2013 11:21 AM


  • Why aren't you just passing the StorageFile from the file picker? A StorageFile is a WinRT type and can be marshalled between the language layers. It's an abstraction for a filename and is what manages permissions to open the file. The pathname itself will not accomplish this for a StorageFile from the file picker.

    P.S. It's best to write components in C++ if you intend to use from JavaScript. With C# you introduce a second managed environment/garbage collector that significantly increases the app's memory footprint.

    Tuesday, October 15, 2013 10:15 PM