Get file extension based on File MimeType – C#
I had implemented a custom workflow to extract the attached email and create an email activity in CRM. Sometimes, users are attaching the email that has untitled attachments. Since the file name is empty for these untitled attachments, it is throwing an error while creating email attachments in CRM.
Hence, I have written a logic to create these attachments inside CRM with the file name “Untitle Attachment #”. While extracting the attachments, I am getting only “Mime Type” and there is no “Extension”.
I have implemented below code to get the Default extension based on MimeType.
using Microsoft.Win32;
public static string GetDefaultExtension(string mimeType)
{
string defaultExt;
RegistryKey key;
object value;
key = Registry.ClassesRoot.OpenSubKey(@”MIME\Database\Content Type\” + mimeType, false);
value = key != null ? key.GetValue(“Extension”, null) : null;
defaultExt = value != null ? value.ToString() : string.Empty;
return defaultExt;
}
This was originally posted here.

Like
Report
*This post is locked for comments