通过注册表获取文件的ContentType
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace ObtainContenttype
{
class Program
{
static void Main(string[] args)
{
GetFileContentType(@"C:\Documents and Settings\roboth_staff\桌面\spx.txt");
}
public static string GetFileContentType(string filename)
{
string[] array = filename.Split('.');
string result = string.Empty;
string suffix = "." + array[array.Length - 1];
RegistryKey rg = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(suffix);
object obj = rg.GetValue("Content Type");
result = obj != null ? obj.ToString() : string.Empty;
rg.Close();
return result;
}
}
}