468,765 Members | 1,090 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

download file to client machine

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.
Jul 21 '05 #1
6 1487
hi
make a link to your file and post it on your page.

cheers

"Nimesh" wrote:
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.

Jul 21 '05 #2
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();
Jul 21 '05 #3
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

--
Sriram Krishnan

http://www.dotnetjunkies.com/weblog/sriram
"Carolina" <cc******@gmx.net> wrote in message
news:f4**************************@posting.google.c om...
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();

Jul 21 '05 #4
Carolina wrote:
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
Jul 21 '05 #5
wolfgang wagner wrote:
Carolina wrote:
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


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
Jul 21 '05 #6
Hans Kesting wrote:


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
Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by atse | last post: by
6 posts views Thread by Nimesh | last post: by
5 posts views Thread by Samuel Shulman | last post: by
6 posts views Thread by raymond_b_jimenez | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.