获取文件 MIME 类型时出错
Error while getting file MIME type
我已使用代码 here 获取文件的 MIME 类型。
AS
public static string GetContentType(string fileName)
{
var extension = Path.GetExtension(fileName);
if (String.IsNullOrWhiteSpace(extension))
{
return null;
}
var registryKey = Registry.ClassesRoot.OpenSubKey(extension);
if (registryKey == null)
{
return null;
}
var value = registryKey.GetValue("Content Type") as string;
return String.IsNullOrWhiteSpace(value) ? null : value;
}
但是 sql 文件总是 returns null。知道我做错了什么吗。
因为注册表项 HKEY_CLASSES_ROOT\.sql
可能没有任何名为 Content Type
的值。您可以通过 regedit
工具手动添加。
我已使用代码 here 获取文件的 MIME 类型。
AS
public static string GetContentType(string fileName)
{
var extension = Path.GetExtension(fileName);
if (String.IsNullOrWhiteSpace(extension))
{
return null;
}
var registryKey = Registry.ClassesRoot.OpenSubKey(extension);
if (registryKey == null)
{
return null;
}
var value = registryKey.GetValue("Content Type") as string;
return String.IsNullOrWhiteSpace(value) ? null : value;
}
但是 sql 文件总是 returns null。知道我做错了什么吗。
因为注册表项 HKEY_CLASSES_ROOT\.sql
可能没有任何名为 Content Type
的值。您可以通过 regedit
工具手动添加。