web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / CRM TIPS By PRM / Get file extension based on...

Get file extension based on File MimeType – C#

P. R. M Profile Picture P. R. M 739

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.

Comments

*This post is locked for comments