/// <summary>

/// Returns the mime type associated with the extension

/// </summary>

/// <param name="extension">Extension of the file type.  Eg. ".pdf"</param>

/// <returns>String.Empty if not found</returns>

public string GetMimeType(string extension)

{

  string mimeType = String.Empty;

 

  // Attempt to get the mime-type from the registry.

  Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension);

  if (regKey != null)

  {

    string type = (string)regKey.GetValue("Content Type");

    if (type != null)

      mimeType = type;

  }

  return mimeType;

}

相关文章:

  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2021-07-17
  • 2021-10-01
  • 2021-10-20
相关资源
相似解决方案