Loading Documents from the Web

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


To write the code in Visual Basic:

  
Visual Basic
Copy Code

Public Sub New()

    InitializeComponent()

    ' load file from the Web

    Dim client As New WebClient()

    AddHandler client.OpenReadCompleted, AddressOf client_OpenReadCompleted

    client.OpenReadAsync(New Uri("http://www.componentone.com/newimages/Products/Documentation/Silverlight.Maps.pdf", UriKind.Absolute))

End Sub

Private Sub client_OpenReadCompleted(sender As Object, e As OpenReadCompletedEventArgs)

       C1PdfViewer1.LoadDocument(e.Result)

End Sub

To write the code in C#: