Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. How to successfully Async download a pdf file to a client PC vb.net web application

How to successfully Async download a pdf file to a client PC vb.net web application

Scheduled Pinned Locked Moved Visual Studio
csharphelpdotnetvisual-studio
2 Posts 2 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amer Amer
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • A Amer Amer

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Amer Amer wrote:

      I don’t know if this question belongs to this forum.

      No, it is not a Visual Studio issue. You should post in the Web Development Discussion Boards[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups