title: Saving pdf document from webbrowser control
body: <p>I'm navigating from webbrowser control to an url like this;
  <a href="http://www.who.int/cancer/modules/Team%20building.pdf" rel="nofollow">http://www.who.int/cancer/modules/Team%20building.pdf</a></p>
  
  <p>It's shown in webbrowser control. What I want to do is to download this pdf file to computer. But I tried many ways;</p>
  
  <pre><code>Dim filepath As String
  filepath = "D:\temp1.pdf"
  Dim client As WebClient = New WebClient()
  client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
  client.DownloadFileAsync(WebBrowserEx1.Url, filepath)
  </code></pre>
  
  <p>This one downloads a pdf but there is nothing in the file.</p>
  
  <p>Also tried with</p>
  
  <pre><code>objWebClient.DownloadFile()
  </code></pre>
  
  <p>nothing changed.</p>
  
  <p>I tried to show a save or print dialog;</p>
  
  <pre><code>WebBrowserEx1.ShowSaveAsDialog()
  WebBrowserEx1.ShowPrintDialog()
  </code></pre>
  
  <p>but they didnt show any dialog. Maybe the last one is because it doesnt wait to load the the pdf into webbrowser completely.</p>
  
  <p>When I try html files there is no problem to dowload, but in this <strong>.pdf</strong> file, I think I didn't manage to wait the file to be loaded as pdf into browser. This function(s);</p>
  
  <pre><code> Private Sub WaitForPageLoad(ByVal adimno As String)
      If adimno = "1" Then
          AddHandler WebBrowserEx1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
          While Not pageReady
              Application.DoEvents()
          End While
          pageReady = False
      End If
  
  End Sub
  
  Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
      If WebBrowserEx1.ReadyState = WebBrowserReadyState.Complete Then
          pageReady = True
          RemoveHandler WebBrowserEx1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
      End If
  End Sub
  </code></pre>
  
  <p>are not working for this situation. I mean it gets into infinite loop. </p>
  
  <p>So anyone knows how to wait this to load pdf then save into computer.</p>