How to download a file (ASP.NET beginner)

S

Sandra

Hi there,

I'm uploading a file to a dedicated ".aspx" page from a "C#" console app (no
browser involved). This file needs to be converted to another format and the
resulting file then sent back (to be saved on the client's machine). I
figured out how to upload the file but can't figure out how to send the
converted file back (probably using "HttpResponse" I assume). Can anyone
help get me started:

1) Where (how) can I store a success/failure code with an appropriate error
message on failure
2) If 1) above is successful, how do I store the converted file so the
client can retrieve it
3) How does the client read both 1 and 2 above (success/failure indicator
with converted file on success or error message on failure)

I really only need the basic methods to investigate as I can probably figure
out the low-level details (I'm an experienced developer but not in ASP.NET).
Thank you.
 
N

Nathan Sokalski

Here is the code I use to let users download code from my site:

Response.ClearContent()
Response.AddHeader("content-disposition", "attachment;filename=" &
CStr(e.CommandArgument))
Response.WriteFile(Server.MapPath("/sourcecode/" &
CStr(e.CommandArgument)))
Response.End()

You can obviously see what methods of the Response object I use, so you can
hopefully find the rest of the details about them in documentation for what
you need to do. The only other thing here that you may want to take note of
is that I use the content-disposition header, which you may also want to
look at the documentation for just to get the details. Hopefully this helps.
 
S

Sandra

Here is the code I use to let users download code from my site:
Response.ClearContent()
Response.AddHeader("content-disposition", "attachment;filename=" &
CStr(e.CommandArgument))
Response.WriteFile(Server.MapPath("/sourcecode/" &
CStr(e.CommandArgument)))
Response.End()

You can obviously see what methods of the Response object I use, so you
can hopefully find the rest of the details about them in documentation for
what you need to do. The only other thing here that you may want to take
note of is that I use the content-disposition header, which you may also
want to look at the documentation for just to get the details. Hopefully
this helps.

That's very helpful (just ran my first successful test). Greatly
appreciated. I still need to look into header details of course, as you
mentioned. I'll do my research first but may be back with a follow-up
question if required (as a new post). Thanks again.
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top