0 votes
by (750 points)
edited by
List<Attachment> lstAllMailContent = new List<Attachment>();
foreach (Attachment objMailContent in lstAllMailContent)
{
    if (objMailContent.ContentDisposition != null)
    {
        string strname = objMailContent.ContentDisposition.FileName;
    }
} 

In the above code I want the name of the attachment for which I use the following statement as follows -

string strname = objMailContent.ContentDisposition.FileName;

can i use objMailContent.FileName ??

what is the difference between the two??

but in some cases i get content disposition null which gives me error.

so tell me what can we do in this?? please find a solution as soon as possible thanks

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (58.9k points)
edited by

Attachment.FileName is the suggested way to go unless you need to dive deeper. This property abstracts you from the low level problems (e.g. ocasionally some emails out in the wild lack the MIME header Content-Disposition - that's where you get the Attachment.ContentDisposition = null. Some email attachments also lack the filename and then we have to generate the Attachment.FileName).

So the difference between:

Attachment.FileName and Attachment.ContentDisposition.FileName
is that the latter gives you access to the low level MIME headers, and you have to take care of the possible missing ContentDisposition header, etc.
And the first property also gives you access to the attachment filename but it automatically fixes the actual filename when needed.

...