467,211 Members | 1,213 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,211 developers. It's quick & easy.

Multi file download

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
Nov 18 '05 #1
  • viewed: 2027
Share:
3 Replies
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

"Skwish" <st************@comcast.net> wrote in message
news:3r********************@comcast.com...
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

Nov 18 '05 #2
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
"Hermit Dave" <he***********@CAPShotmail.com> wrote in message
news:el**************@TK2MSFTNGP09.phx.gbl...
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

"Skwish" <st************@comcast.net> wrote in message
news:3r********************@comcast.com...
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


Nov 18 '05 #3
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

"Skwish" <st************@meck.com> wrote in message >
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
"Hermit Dave" <he***********@CAPShotmail.com> wrote in message
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

"Skwish" <st************@comcast.net> wrote in message
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



Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Frank Jona | last post: by
2 posts views Thread by Derrick | last post: by
1 post views Thread by Bob Rock | last post: by
reply views Thread by Buddy Ackerman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.