locked
How to convert local path from FileOpenPicker to URI?

    Question

  • From FileOpenPicker I can get the local path like 'C:\Users\Name\Pictures'. How can I convert to Metro URI to something like Uri('ms-appx:///images/logo.png' ?


    Charlie Chang L

    Thursday, September 13, 2012 5:26 AM

Answers

All replies

  • Could you explain what you are attempting to do? These are different locations. The file path is in the users profile folder for pictures, the second you listed is referring to a packaged asset in the app's directory.

    This may help explain the differences:

    How to load file resources (Windows Store apps using C#/VB/C++ and XAML)


    David Lamb

    Thursday, September 13, 2012 11:33 PM
    Moderator
  • My purpose is to get a URI address from FilePicker Path. In limited way only Documents, Picture, Video, Audio are needed. It seems to me there is no way to refer these folders in URI. Although they are local pathes, it is useful to use a unified uri for all devices.  

    Charlie Chang L

    Friday, September 14, 2012 2:20 PM
  • That is correct. The protocol handlers ms-appx (app packaged content) and ms-appdata (app saved data) do not facilitate access to the libraries you mentioned.


    David Lamb

    Friday, September 14, 2012 6:50 PM
    Moderator
  • David is correct, you can't express access to files in libraries using a uri. If you convert the StorageFile to a path you will lose the ability to access that file as you will need to convert it back to a StroageFile to gain access (the file access API is brokered and the object is needed to provide the access).

    if you need to save away a reference to a file you can do that using the StorageItemAcessList class

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.storageitemaccesslist.aspx

    Many apis that accept a uri also take a StorageFile or a RandomAcessStream, see if that satisfies your scenario.

    Chris

    Saturday, September 15, 2012 5:01 AM
  • If I have a path which points to some temporary file location or local storage folder in appdata, can I convert it to URI? Also, what about vice versa? Can I convert a local URI to file path?
    Saturday, September 15, 2012 1:11 PM
  • you can, but WinRT offers no APIs to help you do this. you will have to parse and re-form the strings.
    Monday, September 17, 2012 7:39 PM
  • I think it could have been better if Uri class offers a few more functions: fromLocalPath(), toLocalPath() and isLocalPath().
    Tuesday, September 18, 2012 6:22 AM