3 Replies - 1462 Views - Last Post: 11 March 2010 - 05:31 AM

#1 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Downloading (pushing) large files

Posted 18 May 2007 - 05:33 AM

Description: Filepath should point to the file, Filename is the name used to save the file. (dont forget the extension)The response object has a built in maximum on memory usage. If you want to push files in the traditional way, that is read it in and then echo it out, you will run into this limit. This sniplet uses chunks to get around this problem.
sub SendFileToResponse(FilePath, FileName)
     dim clChunkSize, oStream, length
     
      clChunkSize = 1048576 
     Response.Buffer = false

     Response.ContentType = "application/octet-stream"
     Response.AddHeader "Content-Disposition", "attachment; Filename=" + FileName 

     set oStream = Server.CreateObject("ADODB.Stream")
     oStream.Type = 1 
     oStream.Open()
     oStream.LoadFromFile(FilePath)

     Response.AddHeader "Content-Length", oStream.Size

     length = int (oStream.Size / clChunkSize)
     for i = 1 to length
          Response.BinaryWrite oStream.Read(clChunkSize) 
     next
     
     if ((oStream.Size mod clChunkSize) <0) then
          Response.BinaryWrite oStream.Read(oStream.Size mod clChunkSize) 
     end if
     oStream.Close()
end sub


Is This A Good Question/Topic? 0
  • +

Replies To: Downloading (pushing) large files

#2 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Downloading (pushing) large files

Posted 18 May 2007 - 05:33 AM

Description: Filepath should point to the file, Filename is the name used to save the file. (dont forget the extension)The response object has a built in maximum on memory usage. If you want to push files in the traditional way, that is read it in and then echo it out, you will run into this limit. This sniplet uses chunks to get around this problem. edit 10/09/09: fixed a bug!
sub SendFileToResponse(FilePath, FileName)
     dim clChunkSize, oStream, length
     
      clChunkSize = 1048576 
     Response.Buffer = false

     Response.ContentType = "application/octet-stream"
     Response.AddHeader "Content-Disposition", "attachment; Filename=" + FileName 

     set oStream = Server.CreateObject("ADODB.Stream")
     oStream.Type = 1 
     oStream.Open()
     oStream.LoadFromFile(FilePath)

     Response.AddHeader "Content-Length", oStream.Size

     length = int (oStream.Size / clChunkSize)
     if(length > 0) then
          for i = 1 to length
               Response.BinaryWrite oStream.Read(clChunkSize) 
          next
     end if

     if ((oStream.Size mod clChunkSize) >0) then
          Response.BinaryWrite oStream.Read(oStream.Size mod clChunkSize) 
     end if
     oStream.Close()
end sub

Was This Post Helpful? 0
  • +
  • -

#3 jostorero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-February 10

Re: Downloading (pushing) large files

Posted 01 February 2010 - 02:12 AM

Hi Trogdor, Do you know if it works in IIS7 ?
Was This Post Helpful? 0
  • +
  • -

#4 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Downloading (pushing) large files

Posted 01 February 2010 - 06:10 AM

Never tried, it is oldskool asp5 that this was made in. You are welcome to try and report the result.
Was This Post Helpful? 0
  • +
  • -

#5 shalinichaudhary  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 1
  • Joined: 11-March 10

Re: Downloading (pushing) large files

Posted 11 March 2010 - 05:31 AM

plzz send this code in c#
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1