//file path
string file_ddr_service_agreement = HttpContext.Current.Server.MapPath(@"~\service_solutions\freedom_to_learn\FTL_online\myorder\schoolpages\Direct_Debit_Agreement-2013\") + "Computelec DDR Agreement.pdf";
//attachment object
Attachment ddr_service_agreement = new Attachment(file_ddr_service_agreement,MediaTypeNames.Application.Pdf);
ContentDisposition disposition = ddr_service_agreement.ContentDisposition;
//setting attachment info for each attachment
disposition.CreationDate = File.GetCreationTime(file_ddr_service_agreement);
disposition.ModificationDate = File.GetLastWriteTime(file_ddr_service_agreement);
disposition.ReadDate = File.GetLastAccessTime(file_ddr_service_agreement);
disposition.FileName = Path.GetFileName(file_ddr_service_agreement);
disposition.Size = new FileInfo(file_ddr_service_agreement).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
if (ddr_service_agreement != null)
{
//add the attachment
mailMessage.Attachments.Add(ddr_service_agreement);
}
Explanation of ContentDisposition class from MSDN:
The information in the ContentDisposition class accompanies an e-mail message that contains attachments when the e-mail message is sent to its destination. The information inContentDisposition can be used by software that displays e-mail to present the e-mail attachments in the manner intended by the sender.
E-mail messages are created using instances of the MailMessage class. Instances of the Attachment class are used to add attachments to e-mail messages. To modify theContentDisposition for an attachment, get the instance from the Attachment.ContentDisposition property.
Content to be displayed as part of the message body has the disposition type of Inline. Content that is not displayed but is attached in a separate file has the disposition type ofAttachment. Use the Inline property to control the disposition type for the attachment associated with an instance of ContentDisposition.
For file attachments, you can use the properties of the ContentDisposition to set the file size, as well as the date the file was created, last read, and last modified. For all attachments, you can set a recommended file name in the event that the attachment is stored on the receiving computer.
The ToString method returns the Content-Disposition header. The Content-Disposition header is described in RFC 2183 available at http://www.ietf.org.
Reference:http://msdn.microsoft.com/library/vstudio/system.net.mime.contentdisposition