Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web-base email client that connects to a pop3.client. I get the emails and everything and I've found code to download the files directly without asking the user.

This makes the email loading slower because it has to download all files before it can save the info on the database an show it on the page.

Is there a way I could use a save dialog to download each file? Keep in mind that the type of file is unknown because it comes as part of the email message. I've researched about the response.transmitfile() but that won't do because I don't know the path to the file (it is in the mail object).

I've also seen the reponse.binarywrite and response.outputstream which should do this, I just don't know how to do it, and all the sample codes I can find are based on the assumption that the file is saved in an app_folder or dynamically generated.

I think if I can get the filebytes and store them to an array I could do this but again, I just don't know how.




Original question: How can I use a save dialog to download an email attachment from a pop3 server in asp.net?
Posted
Updated 29-Mar-12 23:46pm
v3
Comments
Slacker007 30-Mar-12 5:47am    
Edits made: Shortened title and formatting.

1 solution

Did I understand correctly: you're downloading an email with attachments using pop3 protocol and storing everything in your database.
Are attachments also in the database or what?

To force browser to display 'Save' dialog use something like this:
C#
private void SendResponse(string downloadName, byte[] responseBytes)
{
	System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
	response.Clear();
	response.AddHeader("Content-Type", "binary/octet-stream");
    	response.AddHeader("Content-Disposition", "attachment; filename=" + 
            downloadName + "; size=" + responseBytes.Length.ToString());
	response.BinaryWrite(responseBytes);
	response.Flush();
	response.End();
}


In this example file content is in byte[], but it can easily be modified to use Streams.
 
Share this answer
 
Comments
Member 8491154 28-Jun-12 8:28am    
I want to save the attachment coming from the email (pop3). How can i do this? Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900