How to download a file (ASP.NET beginner)

  • Thread starter Thread starter Sandra
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top