How to successfully Async download a pdf file to a client PC vb.net web application
-
I don’t know if this question belongs to this forum. I'm developing a website with vb.net web application using visual studio 2015 where a client is able to download a pdf file and I have considered 2 approaches as follows.
Dim sqlcom As New SqlCommand("select bookcontent,bookname from books where bookn=" & Page.RouteData.Values("bookn").ToString & "", conn)
Dim da As New SqlDataAdapter(sqlcom)
Dim ds As New DataTable
da.Fill(ds)
Dim filename As String = ds.Rows(0)("bookcontent").ToString
Dim fff As String = ds.Rows(0)("bookname").ToString
Dim fileInfo As FileInfo = New FileInfo(filename)
If fileInfo.Exists Then
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "Application/pdf"
Response.ContentType = "application/ms-word"
Response.AddHeader("Content-Disposition", "inline; filename=""" & ds.Rows(0)("bookname").ToString & ".pdf" & """")
Response.AddHeader("Content-Length", fileInfo.Length.ToString())
Response.TransmitFile(filename)
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()I'm having trouble with the first approach above because when downloaded start the website Hang on until pdf file fully downloaded to client PC ,this is bad since website will be access By thousand of users every day,so I want to make the download process asynchronous. I use the .NET Framework WebClient class in the second approach:
Dim Client As New WebClient
Dim weburl As String= ....here is some procedure to get url
Client.DownloadFileAsync(New Uri(weburl), @"c:\myfile.pdf")But the problem here is that a path must be set and I want clients to get the file in the default download folder according to the Internet browser they use and the download process not appear through browser user can't see downloading file progress . I will very much appreciate any comment that points me in the direction to solve this issue. Thanks a lot.
-
I don’t know if this question belongs to this forum. I'm developing a website with vb.net web application using visual studio 2015 where a client is able to download a pdf file and I have considered 2 approaches as follows.
Dim sqlcom As New SqlCommand("select bookcontent,bookname from books where bookn=" & Page.RouteData.Values("bookn").ToString & "", conn)
Dim da As New SqlDataAdapter(sqlcom)
Dim ds As New DataTable
da.Fill(ds)
Dim filename As String = ds.Rows(0)("bookcontent").ToString
Dim fff As String = ds.Rows(0)("bookname").ToString
Dim fileInfo As FileInfo = New FileInfo(filename)
If fileInfo.Exists Then
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "Application/pdf"
Response.ContentType = "application/ms-word"
Response.AddHeader("Content-Disposition", "inline; filename=""" & ds.Rows(0)("bookname").ToString & ".pdf" & """")
Response.AddHeader("Content-Length", fileInfo.Length.ToString())
Response.TransmitFile(filename)
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()I'm having trouble with the first approach above because when downloaded start the website Hang on until pdf file fully downloaded to client PC ,this is bad since website will be access By thousand of users every day,so I want to make the download process asynchronous. I use the .NET Framework WebClient class in the second approach:
Dim Client As New WebClient
Dim weburl As String= ....here is some procedure to get url
Client.DownloadFileAsync(New Uri(weburl), @"c:\myfile.pdf")But the problem here is that a path must be set and I want clients to get the file in the default download folder according to the Internet browser they use and the download process not appear through browser user can't see downloading file progress . I will very much appreciate any comment that points me in the direction to solve this issue. Thanks a lot.