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. Web Development
  3. ASP.NET
  4. downloading a large file using asp.net 2.0 with C#

downloading a large file using asp.net 2.0 with C#

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netdatabasesysadmin
4 Posts 4 Posters 0 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.
  • G Offline
    G Offline
    ganeshMohan
    wrote on last edited by
    #1

    hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance

    Known is a drop , Unknown is an Ocean

    E V L 3 Replies Last reply
    0
    • G ganeshMohan

      hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance

      Known is a drop , Unknown is an Ocean

      E Offline
      E Offline
      eyeseetee
      wrote on last edited by
      #2

      Can you explain a bit more your problem, what do you mean by

      ganeshMohan wrote:

      my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines.

      Whats the code above for, is it from the downloaded file? Where are you downloading the file from?

      1 Reply Last reply
      0
      • G ganeshMohan

        hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance

        Known is a drop , Unknown is an Ocean

        V Offline
        V Offline
        Vasudevan Deepak Kumar
        wrote on last edited by
        #3

        Try Response.WriteFile or Response.TransmitFile.

        Vasudevan Deepak Kumar Personal Homepage
        Tech Gossips
        A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

        1 Reply Last reply
        0
        • G ganeshMohan

          hai my code: Response.Clear(); Response.AppendHeader("Content-Disposition","attachment; filename=" + filename); Response.AppendHeader("Content-Length", filename.Length.ToString()); Response.ContentType = "text/plain"; //if pdf file "application/pdf" string strMapPath = Server.MapPath("~FolderName/filename); FileStream fs = new FileStream(strMapPath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite); long bytesToGo; int bytesRead; Byte[] buffer = new byte[1048576]; bytesToGo = fs.Length; while (bytesToGo > 0) { bytesRead = fs.Read(buffer, 0, 1048576); Response.OutputStream.Write(buffer, 0, bytesRead); Response.Flush(); bytesToGo -= bytesRead; } fs.Close(); Response.End(); my problem is downloaded file .sql file[size:4mb], which was not fully downloaded, it partially downloaded.i.e the download file doesn't show the full content it shows only 10 or 15 lines. if anyone known about this,help me Thanks in Advance

          Known is a drop , Unknown is an Ocean

          L Offline
          L Offline
          l0kke
          wrote on last edited by
          #4

          wild guess, isn't problem in this line: Response.AppendHeader("Content-Length", filename.Length.ToString()); where you are saying that content of the response is as long as length of the filename? Pilo

          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