C# Get file extension by content type

C#
Copy to clipboard
fablecode
  1. // Source: http://stackoverflow.com/questions/23087808/c-sharp-get-file-extension-by-content-type
  2.  
  3. public static string GetDefaultExtension(string mimeType)
  4. {
  5.   string result;
  6.   RegistryKey key;
  7.   object value;
  8.  
  9.   key = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type\" + mimeType, false);
  10.   value = key != null ? key.GetValue("Extension", null) : null;
  11.   result = value != null ? value.ToString() : string.Empty;
  12.  
  13.   return result;
  14. }
  15.  
  16.  

    Leave a comment

     
    Visual verification
     

    Related books

    More InfoLearn C# in One Day and Learn It Well: C# for Beginners with Hands-on Project (Learn Coding Fast with Hands-On Project) (Volume 3)
    Learn C# in One Day and Learn It Well: C# for Beginners with Hands-on Project (Learn Coding Fast with Hands-On Project) (Volume 3)
    More InfoC# 6.0 and the .NET 4.6 Framework
    C# 6.0 and the .NET 4.6 Framework
    More InfoThe C# Player's Guide (3rd Edition)
    The C# Player's Guide (3rd Edition)
    More InfoMicrosoft Visual C# Step by Step (8th Edition) (Developer Reference)
    Microsoft Visual C# Step by Step (8th Edition) (Developer Reference)
    More InfoThe C# Player's Guide (2nd Edition)
    The C# Player's Guide (2nd Edition)
    More InfoC# Programming: The No-Nonsense Guide: Learn C# Programming Within 12 Hours! (Including A Free C# Cheatsheet & 30+ Exercises)
    C# Programming: The No-Nonsense Guide: Learn C# Programming Within 12 Hours! (Including A Free C# Cheatsheet & 30+ Exercises)
    More InfoC# 6.0 in a Nutshell: The Definitive Reference
    C# 6.0 in a Nutshell: The Definitive Reference
    More InfoC#: C# Crash Course - The Complete Beginner's Course to Learn C# Programming in 15 Clear-Cut Lessons - Including Dozens of Practical Examples & Exercises (C# Series)
    C#: C# Crash Course - The Complete Beginner's Course to Learn C# Programming in 15 Clear-Cut Lessons - Including Dozens of Practical Examples & Exercises (C# Series)