How to download attachments with asp.net

0 votes
asked Jul 27, 2010 by Dan Billingsley (160 points)
edited Aug 10, 2010

I'm trying to make a Silverlight email client. Since there's no direct IMAP connection possible from silverlight, I've wrapped the email objects in objects. Attachments are the biggest challenge.

One thing I'm considering is having my silverlight application launch a browser window, specifying a message id and attachment, and trying to just kick in the standard browser download functionality.

Has anyone else written any asp.net email clients with these tools, or know what exactly I'd need to write?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Jul 28, 2010 by Jan Sotola (16,920 points)
edited Jul 28, 2010

Actually, this situation is not described in any Rebex MAIL sample, although something similar is used in samples for Rebex ZIP.

If I understand your problem well, the trick you are looking for is writing the attachment into HTTP Response stream. Core of the solution is shown in following code snippet:

Attachment attachment;

// ...retrieve the attachment from mail message...

Response.Clear();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + attachment.FileName);
attachment.Save(Response.OutputStream);
Response.End();
...