For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > October 2006 > How to change name of attachment









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to change name of attachment
TomislaW

2006-10-30, 7:31 pm

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("mail@company.com", 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_My
DocName.doc"

Is there any way to change this attachment name?


Tomislav

Kevin Spencer

2006-10-30, 7:31 pm

Set the Name property of the Attachment.

--
HTH,

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

The devil is in the yada yada yada


"TomislaW" <tomislav.vujnovac@gmail.com> wrote in message
news:1162229755.665196.85790@k70g2000cwa.googlegroups.com...
>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("mail@company.com", 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_My
DocName.doc"
>
> Is there any way to change this attachment name?
>
>
> Tomislav
>



TomislaW

2006-10-31, 7:06 pm


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

tomislav

Kevin Spencer wrote:[color=darkred]
> Set the Name property of the Attachment.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Short Order Coder
> http://unclechutney.blogspot.com
>
> The devil is in the yada yada yada
>
>
> "TomislaW" <tomislav.vujnovac@gmail.com> wrote in message
> news:1162229755.665196.85790@k70g2000cwa.googlegroups.com...

Kevin Spencer

2006-10-31, 7:06 pm

> 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

"TomislaW" <tomislav.vujnovac@gmail.com> wrote in message
news:1162281405.478350.45740@f16g2000cwb.googlegroups.com...
>
> ContentDisposition.FileName should be changed and not Name property of
> the Attachment
>
> tomislav
>
> Kevin Spencer wrote:
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com