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. C#
  4. File downloader 'resume' problem

File downloader 'resume' problem

Scheduled Pinned Locked Moved C#
csharphelpquestioncareerworkspace
6 Posts 3 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.
  • T Offline
    T Offline
    TCHamilton
    wrote on last edited by
    #1

    I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data

    L F 2 Replies Last reply
    0
    • T TCHamilton

      I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data

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

      TCHamilton wrote:

      Since some files are large I want to be able to pause/resume the download.

      In that case, why not check out the Background Intelligent Transfer Service[^]?

      "I do not care if it works on your system, I am not gonna ship your computer."

      T 1 Reply Last reply
      0
      • T TCHamilton

        I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data

        F Offline
        F Offline
        Fayu
        wrote on last edited by
        #3

        Check this post. This might help.

        T 1 Reply Last reply
        0
        • L Lost User

          TCHamilton wrote:

          Since some files are large I want to be able to pause/resume the download.

          In that case, why not check out the Background Intelligent Transfer Service[^]?

          "I do not care if it works on your system, I am not gonna ship your computer."

          T Offline
          T Offline
          TCHamilton
          wrote on last edited by
          #4

          Hi Eddy, I'm not familiar yet with BITS - will explore now. The issue really is how/what's missing in my attempt to facilitate 'resume a paused download...' Web site is public facing that supports various browsers - I've been asked to make sure it can handle IE6 and Safari primarily, not sure if BITS is relevent in that context. I'm sure the target browser limitation will relax, but first I need to get 'resume' to work.

          Tom

          1 Reply Last reply
          0
          • F Fayu

            Check this post. This might help.

            T Offline
            T Offline
            TCHamilton
            wrote on last edited by
            #5

            Still having problem - unable to set the Response Headers :

            Response.AddHeader("Content-Disposition", "attachment; filename=" + Convert.ToString(Server.UrlDecode(Request["FileName"])));

            Response.AddHeader("Content-Length", dlStream.Length.ToString());

            The system gives message that: Headers: 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException' The system is Win2k3 IIS6. VS2k5 Confused... Thank you for any help or suggestions

            Tom

            T 1 Reply Last reply
            0
            • T TCHamilton

              Still having problem - unable to set the Response Headers :

              Response.AddHeader("Content-Disposition", "attachment; filename=" + Convert.ToString(Server.UrlDecode(Request["FileName"])));

              Response.AddHeader("Content-Length", dlStream.Length.ToString());

              The system gives message that: Headers: 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException' The system is Win2k3 IIS6. VS2k5 Confused... Thank you for any help or suggestions

              Tom

              T Offline
              T Offline
              TCHamilton
              wrote on last edited by
              #6

              Well, mystery solved - response headers were being set, just not obvious with IIS 6, have to track them down via DEBUG/Watch with code that can enum the Custom Header array ((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Name "Accept-Ranges" ((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Value "bytes" Able to verify Header set, and respond to resume download 'Range' Thanks all

              Tom

              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