How to download a file from Server to client

  • Thread starter Thread starter ad
  • Start date Start date
Thanks,

I want to download file from the virtual directory of my web application.
The file name is mine.zip.
But the first parameter of the WebClient.DownloadFile is URI.

How can I give the first parameter of the WebClient.DownloadFile() ?
 
It will not ask user when I use WebClient.DownloadFile do download a file
from server.
But I wnat that the user can confirm before download.
How can I do ?
 
Erm, perhaps by using a MessageBox.Show before calling DownloadFile?

Or have we miunderstood your usage? (and to be fair, Greg did ask, but you
didn't answer). Is the client an app or a browser? (it makes a big
difference).

Marc
 
OK then; various options:

If the file itself is publicly available on the web-site, then you could
just hyperlink to it (assuming that MIME is a download type, not an inline
type)
Another similar option is to use HttpResponse.TransmitFile; this will push
the file back to the client on the current response.
To prompt for a download box, you want to set the "content-disposition" HTTP
header to "attachment; filename=something.blah" - this should make the
browser display a "Save As..." dialog to save the current response to disk.
You may be able to use this with TransmitFile, and if it fails you could
just pump the stream yourself.
Another way is to change the "content-type" header to
"application/octet-stream"; this catch-all MIME type is generally prompted
to save, but it gives less information about what the file really is. One
advantage, however, is that it /might/ (not definite; haven't tried it) be
possible to set this as a customer header on a folder on your web-server -
so that everything in (for instance) /Download/ gets this MIME type and thus
is prompted for save.

Some starters for 10 ;-p

Marc
 
Back
Top