WebBrowser Control download file in session

后端 未结 2 859
情歌与酒
情歌与酒 2021-02-09 11:07

I\'m using WebBrowser control to navigate through a login page and download a file. Since I can\'t find a way to manage the download automatically with the control

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 11:57

    After one week googling a trying for a solution I found one that is so simple!

    I you what to silently download a file in an HTTPS URL and a webbrowser control just do this.

    1) Log in using the webbrowser 2) use this code to download.

    //build de URL 
    
      string _url = "https://........."
    
      //define a download file name and location
    
      string _filename = @"C:\Users\John\Documents\somefile.pdf";
    
      //create a webcliente
    
      WebClient cliente = new WebClient();
    
      //do some magic here (pass the webbrowser cokies to the webclient)
    
      cliente.Headers.Add(HttpRequestHeader.Cookie, webBrowser1.Document.Cookie);
    
      //and just download the file
    
      cliente.DownloadFile(_urlpdf, _filename);
    

    It solved my problem

提交回复
热议问题