How to download multiple files

M

moondaddy

I have a asp.net app where a user will need to download multiple files at
once.

Below is some sample code I'm using to download a single file which works
perfectly, however, rather than a single file, I need to download all the
image files for a single order being processed by the user. Is it possible
to download a batch or group of files?

Thanks.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Dim sFilePath As String
Dim oFile As IO.FileInfo

'sFilePath = Request.QueryString.Item("FilePath")
sFilePath =
"C:\Inetpub\wwwroot\Charmpix\Images\ItemImages\CustomPhotos\21207
_Image1.JPG"
oFile = New System.IO.FileInfo(sFilePath)

' Clear the current output content from the buffer
Response.Clear()

' Specify that the response is a stream that cannot be read by the
client and must be downloaded
'Response.ContentType = "application/octet-stream"
Response.ContentType = "application/octet-stream; name=" &
oFile.Name

' Add the header that specifies the default filename for the
Download/SaveAs dialog
'Response.AddHeader("Content-Disposition", "attachment filename=" &
oFile.Name)
Response.AddHeader("content-disposition", "attachment;filename=" &
oFile.Name)

' Add the header that specifies the file size, so that the browser
can show the download progress
Response.AddHeader("Content-Length", oFile.Length.ToString())

' Send the file stream to the client
Response.WriteFile(oFile.FullName)

' Stop the execution of this page
Response.End()

End Sub
 
S

Steve C. Orr [MVP, MCSD]

The simplest way would probably be to put all the files into one zip file.
Then it's still easy with only one file to download.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

As for the download multifiles problem you mentioned, I think Steve's
suggestion that use a certain zip file to provide the multi-file download
is reasonable since the Web page's response is stream based and each
request will only return a single response stream. And we generally put
html stream as output when return web page and return a certain file stream
when process file download request. But it's not suitable to put mutlit
file's stream into one response stream since the client browser is unable
to parse it out.
Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top