0

I need to download a pdf files,but when i click on links my browser open it,i dont have download window( save\saveAs\Open). I am using WatIn making login\password than i press on links, i can't use Webreqest to get this files because i need to set cookies, and i can't get cookies from WatIn brower(in this case).

My code

  using (var browser = new IE("https://www.test.com")){
     browser.GoTo(Link);
   int   response = URLDownloadToFile(0, Link, FilePath, 0, 0);

}

In link that open download windowd( save\saveAs\Open) all work,but here my brower just open the file in brower,and i can't save It.

How can i save PDF file with URLDownloadToFile

user3567884
  • 213
  • 1
  • 6
  • 19

1 Answers1

0

You could use a WebClient, this is the simplest way I can think of:

using (var webClient = new WebClient())
{
    webClient.DownloadFile("https://www.test.com", "C:\test.pdf");
}

You can also add a Proxy and Network Credentials if you need them.

EDIT: About the cookie stuff, you can also add those to the WebClient

Community
  • 1
  • 1
Staeff
  • 4,994
  • 6
  • 34
  • 58
  • How can i add them?They dynamicly build evry time after login.That mean i need to buil all over again with webreqest/response and i dont want that. – user3567884 Jun 12 '14 at 13:40
  • Without having it tested, you can extract the cookies from the IE class and add them to the WebClient with the method described earlier http://stackoverflow.com/questions/6137310/getting-a-list-of-cookies-set-using-watin but I really don't know if this will work, you will need to try it – Staeff Jun 12 '14 at 13:48
  • I know all this man, but this is a bank website i can't get cookies that easy, in 60% it works but not with this one. – user3567884 Jun 12 '14 at 14:20