string fileName = @"C:\example.pdf"; ContentType ct = new ContentType(MimeMapping.GetMimeMapping(fileName)); Console.WriteLine("The MIME type of {0} is {1}.", fileName, ct.MediaType);
Attachment attach = new Attachment(@"C:\example.pdf"); ContentType ct = new ContentType(MimeMapping.GetMimeMapping(attach.Name)); attach.ContentType = ct;In this example, the MIME type of the attachment is set based on its file extension. Overall, the System.Net.Mime ContentType class is useful for working with different types of data and ensuring that it is correctly identified and processed.