Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to name an email attachment in .NET?

There are 3 "name" properties on the .NET Attachment class:

Attachment.Name Attachment.ContentType.Name Attachment.ContentDisposition.FileName

I want to send an excel file with the name "foo.xls". Which of these should be set? What's the difference? The docs are not particularly illuminating.

like image 995
ChaseMedallion Avatar asked Oct 23 '25 15:10

ChaseMedallion


1 Answers

The correct one to use is Attachment.Name.

Info for Attachment.ContentType.Name -

When specifying content for a Attachment as a Stream or String, you can use Name to set the name of the file that stores the content on the recipient's system

Info for Attachment.ContentDisposition.FileName -

The FileName property allows the sender to suggest the name to be used to store an e-mail attachment on the recipient's computer. This name is a suggestion only; the receiving system can ignore it. The name must not include path information; any such information is ignored by the receiving computer.

like image 61
Ntellect13 Avatar answered Oct 26 '25 03:10

Ntellect13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!