Forum Cross Platform with Xamarin

Getting Urls of Local Files

I have a Windows / Android PCL app that is downloading .pdf and .mp3 files using PCLStorage. I have verified that the files are downloading properly. To open the mp3 I am just using a webview. When I use an http:// url to play an mp3 in the WebView it works fine, but I can't get any urls to work from the local files.

I have tried the following:

Directly Accessing through PCL:

IFolder rootFolder = FileSystem.Current.LocalStorage;
IFolder folder = await rootFolder.GetFolderAsync("Downloads");
IFile file = await folder.GetFileAsync(Name + "." + ext);
return file.Path;

Trying to just create the path without PCL

return Path.Combine(FileSystem.Current.LocalStorage.Path, "Downloads", Name + "." + ext);

Removing the full path:

return "Downloads/" + Name + "." + ext

The returned path looks something like this:

I have tried:

  • these as relative paths with no prefix
  • paths with a leading / as the prefix
  • paths with C:\ as the path prefix
  • paths using the file:// syntax
  • paths replacing all instances of \ with /

I have read that there is some issue with loading absolute urls, but I can't seem to figure out how to load accessible urls

I am hoping that someone can help me get an accessible Url to
1) open the mp3 in a web view
2) open the pdfs using Device.OpenUri() (eventually i'll try to get the pdfs opening in a web view as well, but may avoid it since there isn't native support)


  • jacobbullockjacobbullock USMember

    I was able to get this working. file:// works fine on Android, but I didn't realize I needed to use ms-appdata://local for UWP. That solved my URL issue that let me work the mp3s into a WebView.

    For viewing PDFs I was able to use SyncFusion's PDFViewer component which worked very quickly. This is much easier than the Xamarin example of using custom web renderer's etc. That didn't actually work for me anyway with downloaded pdfs. Even trying to read the PDF as base64 was failing.

    SyncFusion has a free community license available here:

  • Hi Jacob,
    Have you resolved the issue regarding the loading of mp3 local files in the WebView ?

    I am also facing the same issue for the other files.

Sign In or Register to comment.