By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

How to download multiple files

P: n/a
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\Cus tomPhotos\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


--
mo*******@nospam.com
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"moondaddy" <mo*******@nospam.com> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
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\Cus tomPhotos\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


--
mo*******@nospam.com

Nov 18 '05 #2

P: n/a
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.