download file to client machine

N

Nimesh

Hi All,

I am new to ASP.NET. I need to download a file from server to the client
machine.

Any ideas on how to go about this ?

Thanks In Advance.
 
C

Carolina

You can try something like this:

string FilePath = MapPath("design.doc");
Response.ContentType = "Application/msword";
Response.AppendHeader("content-disposition", "attachment;filename=" + "design.doc");
Response.WriteFile(FilePath);
Response.Flush();
Response.End();
 
S

Sriram Krishnan

If its a static choice, dont do this - as this is really annoying for people
who use download managers - you can't resume the download - and you can't
bookmark the download easily
 
W

wolfgang wagner

Carolina said:
You can try something like this:

string FilePath = MapPath("design.doc");
Response.ContentType = "Application/msword";
Response.AppendHeader("content-disposition", "attachment;filename=" + "design.doc");
Response.WriteFile(FilePath);
Response.Flush();
Response.End();

i do have the same problem. but how does this work for files located on
another machine??
this does not work:


string FilePath = MapPath("file.log");
Response.ContentType = "text/plain";
Response.AppendHeader("content-disposition", "attachment;filename=" +
"http://domain.com/file.log");
Response.WriteFile(FilePath);
Response.Flush();
Response.End();

is there a way to get this working too??

greets
wolfgang
 
H

Hans Kesting

wolfgang said:
i do have the same problem. but how does this work for files located
on another machine??
this does not work:


string FilePath = MapPath("file.log");
Response.ContentType = "text/plain";
Response.AppendHeader("content-disposition", "attachment;filename=" +
"http://domain.com/file.log");
Response.WriteFile(FilePath);
Response.Flush();
Response.End();

is there a way to get this working too??

greets
wolfgang

The AppendHeader line does two things:
- "attachment": makes the "save-box" pop up
- "filename": *suggests* a filename to use on the client-side
It does NOT specify the place to download the file from.

The WriteFile line places the server-file in the response-stream.
It might be possible to use UNC paths to point to a different
server in the local network (local as seen from the server!).
I don't think it is possible to point to a different webserver.
You might want to redirect instead! (also saves some network
traffic: why first get the file from the other server to your server
only to send it out again to the client?)

Hans Kesting
 
W

wolfgang wagner

Hans said:
The AppendHeader line does two things:
- "attachment": makes the "save-box" pop up
- "filename": *suggests* a filename to use on the client-side
It does NOT specify the place to download the file from.

The WriteFile line places the server-file in the response-stream.
It might be possible to use UNC paths to point to a different
server in the local network (local as seen from the server!).
I don't think it is possible to point to a different webserver.
You might want to redirect instead! (also saves some network
traffic: why first get the file from the other server to your server
only to send it out again to the client?)

Hans Kesting

the problem is the location of the downloadable file. i've got a
download script which should "send" the corresponding file (one in
accessible only from internet, the other only from intranet) to the user
depending on his location (internet or intranet) and also insert some
data into a database.

wolfgang
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top