4

I'm really stuck with an issue. I would like to download a PDF/ZIP formatted file from webview but I can't find any solution/tutorial on the internet, I tried to look webview property class.
i have a webview:

WebView x:Name="webviewIntranet" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

and my method:

public IntranetPage()
{
   webviewIntranet.Navigate(new Uri("http://www.testme.com"));
           this.InitializeComponent();
}

I'm able to show the webpage content but nothing happens when a try to download/click to download some files.

Tirolel
  • 928
  • 3
  • 17
  • 43

3 Answers3

3

First of all some reading about what's new in WebView control http://blogs.windows.com/windows/b/appbuilder/archive/2013/07/17/what-s-new-in-webview-in-windows-8-1.aspx

as you can see, WebView hanldes different browser events: It doesn't support showing nothing else than webpages, but WebView.UnviewableContentIdentified event is fired for them http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.unviewablecontentidentified.aspx

Then you can use file association to throw it to the OS (or do what you need with the file throught the uri... i hope)

void webView1_UnviewableContentIdentified(WebView sender, 
    WebViewUnviewableContentIdentifiedEventArgs args)
{
    Windows.Foundation.IAsyncOperation<bool> b = 
    Windows.System.Launcher.LaunchUriAsync(args.Uri);
}
marmots
  • 91
  • 2
  • 4
1

WebView can't download file. Microsoft has tried not to be WebView, a replacement of IE browser. See the answer from MSDN forum.

Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115
0

I think you can do this, but there's quite a bit of manual intervention. Using something like the BackgroundDownloader you can download a file that you have the URI for. Is you want to also intercept web view navigation, then there's a few workarounds for that; for example: here

Community
  • 1
  • 1
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269