PDF for WPF and Silverlight Overview > Task-Based Help > Loading Documents from the Web |
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 or LoadDocumentAsync method. The following code snippet example uses an HTTP request:
Visual Basic |
Copy Code
|
---|---|
Private Sub LoadProtectedDocument(stream As System.IO.MemoryStream, password As String) Try stream.Position = 0 _viewer.LoadDocument(stream, password) Catch x As Exception 'if (x.Message.IndexOf("password") > -1) '{ Dim msg = "This file seems to be password-protected." & vbCr & vbLf & "Please provide the password and try again." C1.Silverlight.C1PromptBox.Show(msg, "Enter Password", Function(text, result) If result = MessageBoxResult.OK Then ' try again using the password provided by the user LoadProtectedDocument(stream, text) End If '} 'else '{ 'throw; '} End Function) End Try End Sub |
C# |
Copy Code
|
---|---|
void LoadProtectedDocument(System.IO.MemoryStream stream, string password) { try { stream.Position = 0; _viewer.LoadDocument(stream, password); } catch (Exception x) { //if (x.Message.IndexOf("password") > -1) //{ var msg = "This file seems to be password-protected.\r\nPlease provide the password and try again."; C1.Silverlight.C1PromptBox.Show(msg, "Enter Password", (text, result) => { if (result == MessageBoxResult.OK) { // try again using the password provided by the user LoadProtectedDocument(stream, text); } }); //} //else //{ // throw; //} } |