Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using web browser control to download file where URL generate file dynamically. First, I have to upload pdf file then website converts the pdf file into excel after conversion process website generates URL contains file id after requesting that URL website create file dynamically and then save dialog comes. How to handle such type of URL?

Example : I have uploaded File name: 123.pdf

After conversion process webiste generates Url: https:www.123.com/api/download/562362

Then,

When I click on that Url save dialog comes and downloaded file name will be 123.xlsx

How to download the file without showing save dialog? (I m not able to download programmatically.)

What I have tried:

 Dim Download_link As String
    Dim FileName As String
    Dim Final_File_Name As String
    Dim savepath = Application.StartupPath & "\BACKUP\"
Private Sub Download_Click(sender As Object, e As EventArgs) Handles Download.Click
        For Each Ele As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
            If Ele.GetAttribute("InnerText").Contains("Click here to download it.") Then
                Dim s As String = Ele.GetAttribute("href")
                Download_link = s
                MsgBox(s)
                Dim FileName As String = Me.WebBrowser1.Document.GetElementById("file-field-label").InnerText
                Dim objReq As WebRequest = WebRequest.Create(Download_link)
                Dim objResp As WebResponse = objReq.GetResponse()
                Dim objStream As Stream = objResp.GetResponseStream()
                Dim reader As StreamReader = New StreamReader(objStream, Encoding.ASCII)
                Dim fStream As FileStream = New FileStream(savepath & FileName, FileMode.Create)
                Dim writer As StreamWriter = New StreamWriter(fStream)
                writer.Write(reader.ReadToEnd())
                objStream.Close()
                reader.Close()
                writer.Close()
                fStream.Close()
            End If
        Next
    End Sub
Posted
Updated 31-Mar-19 23:36pm
v2

1 solution

You can't download without that dialog, it is a security feature of the browser. You will need to download the file programatically. Rather than continuing with your current solution you should work to fix the reason why you can't down it programatically.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900