This project is read-only.

How do i find the size of the attached file?

Jun 5, 2012 at 9:09 AM

I have the following code and I want to find the size of the attached document in integer. How do I do it?

bool attachment = false;
List<MailContent> lstAttachment = MailMessage.GetAttachedContents(mg);
if (lstAttachment.Count != 0)
          attachment = true;
   foreach (MailContent attach in lstAttachment)
       int size= attach. (What ???);

Jun 6, 2012 at 12:34 AM

You can get the actual text data of this mail by Data property of MailMessage object.
And you can get the size of text by Length property of String object.

MailContent attach = .....;
var fileSize = attach.Data.Length;

If you want to get actual file size, you must save file by DecodeData method of MailContent object and read file size by System.IO.FileInfo class.
Perhaps, attach.Data.Length is not equal to actual file size.