Multi file download

  • Thread starter Thread starter Skwish
  • Start date Start date
S

Skwish

Hi,
I would like to download all the files from a folder (of various types i.e.
..txt, .dll, .dat, etc.). I tried

Dim MyDir As IO.Directory
Dim path As String = Me.MapPath(".") & "\Data"
Dim dirs As String() = IO.Directory.GetFiles(path)
Dim iLoop As Integer
Dim FileName As String
'Set the appropriate ContentType.
Response.ContentType = "multipart/mixed"

For iLoop = dirs.GetLowerBound(0) To dirs.GetUpperBound(0) - 1
FileName = dirs(iLoop).Substring(dirs(iLoop).LastIndexOf("\") + 1)
Response.AppendHeader("Content-Disposition", "attachment; filename=" &
FileName)
Response.WriteFile(dirs(iLoop))
Next

This gets a single file with the name of the first file with all the files
combined. I have tried the multipart/mixed, but I not sure what to use as a
boundry or how to get the multiple filenames.

Any advice would be appreciated,

Thanks,

Stephen
 
create a seperate page to which you can pass the file name to be downloaded
and use response.contenttype and the rest of the code

what's happening right now is that its all coming as a part of one response
stream. you need to write the code to be intelligent enough to only
response.write one file and then release the stream
and start again with another call to the download page with another response
stream to serve

Regards,

HD
 
O.K. Dave,

I tried this

Dim MyDir As IO.Directory
Dim path As String = Me.MapPath(".") & "\Data"
Dim dirs As String() = IO.Directory.GetFiles(path)
Dim iLoop As Integer
Dim FileName As String

For iLoop = dirs.GetLowerBound(0) To dirs.GetUpperBound(0) - 1
Response.Redirect("Download.aspx?filename=" & dirs(iLoop), false)
Next

I still get only one file (the first one if I use false to not terminate the
page and the second file if I use true to terminate). How do I stop the
stream after the first call and start again with the next one?

Thanks for the help,

Stephen
 
Okay here what i think you should do to achieve this.
A Response cannot be initiated by itself
It only starts when there is a request from client.
So when the user clicks download.
1. Do a post to the server. Get the list of files
2. To self initiate a request from you can use register client block (put
the calls to the download file into client side javascript)
3. Create an array of files in javascript (client side)
4. use a for loop and within the for loop initiate a request to the server
using window.open("your download file.asp?filename=" +
filearray[currentpos])
5. This should initiate a request to the server to which your download page
can now respond to. you just have to request the request filename parameter
and check for its existance in your path... and start writing to response
stream.

This should should work.... something like going all the way but i am not
aware of any way you can initiate a response without client request.

HTH

HD
 
Back
Top