locked
Accessing appdata/temp folder in web context

    Question

  • I have a metro app in JavaScript which hosts a webcontext using irfame referenced via ms-appx-web scheme. Now this webpage needs to access a few images copied into application's temp and appdata local folder, referencing it via ms-appdata scheme does not work and raises a security exception.

    Is there a way to access those files in web context? I know ms-appx-web refers to the applications's root but is there a temporary folder/appdata scheme for web context too?

    Please help.
    Thanks in advance.

    Monday, June 25, 2012 6:56 PM

Answers

  • You cannot use the Windows API (WinRT) from the script running in the web context, so you will not be able to use locations such as Windows.Storage.ApplicationData.localFolder in that way.  You'd have to use a path that the web context has access to and then use postMessage to pass that data back & forth between the local and web contexts, if needed.

    I'm not sure what your external JavaScript requirement enforces, but depending on your requirements, perhaps localStorage or sessionStorage would work for your needs?  Those are web standards and so should be useable from both the local and web contexts.  See http://msdn.microsoft.com/en-us/library/cc197062(v=VS.85).aspx for information on going this route.  How would you use this external API in a normal web browser application?  That might be the route you need to take and then use postMessage back to your app's local context if it needs to share any data from the call, etc.


    This posting is provided "AS IS" with no warranties, and confers no rights.


    Tuesday, June 26, 2012 6:33 AM

All replies

  • You will need to read the local folders in the local context, not web context.  You can then use postMessage to send that data into the web context.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, June 25, 2012 8:27 PM
  • It wont help me. A remote java script requires a file path as arguement not the file data, the interface of remote java script is beyond the app's control.

    There should be a folder in which application can download or create files and web context should be able to read that folder, otherwise how will it work? How can I fix this?

    Tuesday, June 26, 2012 5:34 AM
  • You cannot use the Windows API (WinRT) from the script running in the web context, so you will not be able to use locations such as Windows.Storage.ApplicationData.localFolder in that way.  You'd have to use a path that the web context has access to and then use postMessage to pass that data back & forth between the local and web contexts, if needed.

    I'm not sure what your external JavaScript requirement enforces, but depending on your requirements, perhaps localStorage or sessionStorage would work for your needs?  Those are web standards and so should be useable from both the local and web contexts.  See http://msdn.microsoft.com/en-us/library/cc197062(v=VS.85).aspx for information on going this route.  How would you use this external API in a normal web browser application?  That might be the route you need to take and then use postMessage back to your app's local context if it needs to share any data from the call, etc.


    This posting is provided "AS IS" with no warranties, and confers no rights.


    Tuesday, June 26, 2012 6:33 AM