ComponentOne PdfViewer for WPF and Silverlight
PdfViewer for WPF and Silverlight Overview / Task-Based Help / Loading Documents from the Web
In This Topic
    Loading Documents from the Web
    In This Topic

    To load a file from the Web you must first download it to your application using an asynchronous request object such as HttpClient. Then you simply pass the resulting stream to the LoadDocument method . The following code snippet example uses an HTTP request:

    Visual Basic
    Copy Code
    Private Sub LoadDocument()
     
            ' load file from the Web
            Dim client As New HttpClient()
          
            Dim url As String = "http://cdn.componentone.com/files/win8/Win8_UXG_RTM.pdf"
          
            Try
             Dim stream = Await client.GetStreamAsync(New Uri(url, UriKind.Absolute))
                pdfViewer.LoadDocument(stream)
          
            Catch
     
                Dim dialog = New MessageDialog("There was an error attempting to download the document.")
                dialog.ShowAsync()
         
            End Try
        End Sub
    

     

    C#
    Copy Code
    private async void LoadDocument()
     
    {
     
     
      // load file from the Web
     
        HttpClient client = new HttpClient();
     
        string url = “http://cdn.componentone.com/files/win8/Win8_UXG_RTM.pdf”;
      
        try
     
        {
     
            var stream = await client.GetStreamAsync(new Uri(url, UriKind.Absolute));
          
            pdfViewer.LoadDocument(stream);
     
        }
     
        catch
      
    {
     
       
        var dialog = new MessageDialog("There was an error attempting to download the document.");
     
            dialog.ShowAsync();
        }
    }