How to change name of attachment

T

TomislaW

I am sending word document with e-mail from asp.net 2.0 application.
I read doc file like this:FileStream fs =
System.IO.File.Open(docPath,FileMode.Open,FileAccess.Read,FileShare.Read);
Then create message:
MailMessage message = new MailMessage("(e-mail address removed)", email);
message.Subject = "Subject";
message.Body = "";
ContentType ct = new ContentType("application/vnd.ms-word");
Attachment data = new Attachment(ms,ct);

And I get mail message with attachment name
"c__inetpub_wwwroot_MyAppName_MyFolder_MyDocName.doc"

Is there any way to change this attachment name?


Tomislav
 
T

TomislaW

ContentDisposition.FileName should be changed and not Name property of
the Attachment

tomislav
 
K

Kevin Spencer

ContentDisposition.FileName should be changed and not Name property of
the Attachment

Sorry, wrong answer. The Name property of the System.Net.Mail.Attachment
class sets the value of the "name" parameter of the Content-Type header for
the Attachment. This is used by the Attachment class to create the header. I
have been running a service that sends emails using the System.Net.Mail
namespace classes for over a year now, and use the Name property of the
Attachment to set the file name. The Attachments are actually created from
strings, not files, and the Name property sets the file name that is sent to
the client.

The following is an excerpt from the header of one of these emails, each of
which includes multiple attachments:

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KCGE 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KCGS 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KESN 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KFDK 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KFME 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KRJD 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KW29 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for K2G4 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="AWOS Client Report for KCBE 10-30-2006.txt"
Content-Transfer-Encoding: base64

----boundary_30_1d665342-2ec3-494e-9c20-acc8d3b1df7f
Content-Type: text/plain;
name="DSI AWOS Services Distribution Report for 10/30/2006 3:45:56 AM.txt"
Content-Transfer-Encoding: base64

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

The devil is in the yada yada yada
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top