什么';是.Net替换文件.Type FileSystemObject属性吗?
在经典Asp中,我们使用该属性从注册表中获取与文件类型关联的友好名称(例如“.txt”的“文本文档”)。通常替换旧COM对象的FileInfo类不复制此功能,到目前为止,我在搜索替换对象方面没有太大成功。我不知道BCL中有什么方法,但您可以从注册表轻松读取它:什么';是.Net替换文件.Type FileSystemObject属性吗?,.net,filesystemobject,.net,Filesystemobject,在经典Asp中,我们使用该属性从注册表中获取与文件类型关联的友好名称(例如“.txt”的“文本文档”)。通常替换旧COM对象的FileInfo类不复制此功能,到目前为止,我在搜索替换对象方面没有太大成功。我不知道BCL中有什么方法,但您可以从注册表轻松读取它: using System; using Microsoft.Win32; class Program { static void Main(string[] args) { string extensi
using System;
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
string extension = ".txt";
string nicename = "";
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(extension))
{
if (key != null)
{
string filetype = key.GetValue(null) as string;
using (RegistryKey keyType = Registry.ClassesRoot.OpenSubKey(filetype))
{
if (keyType != null)
{
nicename = keyType.GetValue(null) as string;
}
}
}
}
Console.WriteLine(nicename);
}
}
但是,Vladimir提供的中使用的方法是首选的,因为它使用API接口。我希望避免手动读取值,但考虑到我可能会选择这条路线,我认为这里已经回答了:可能重复