Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';是.Net替换文件.Type FileSystemObject属性吗?_.net_Filesystemobject - Fatal编程技术网

什么';是.Net替换文件.Type FileSystemObject属性吗?

什么';是.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

在经典Asp中,我们使用该属性从注册表中获取与文件类型关联的友好名称(例如“.txt”的“文本文档”)。通常替换旧COM对象的FileInfo类不复制此功能,到目前为止,我在搜索替换对象方面没有太大成功。

我不知道BCL中有什么方法,但您可以从注册表轻松读取它:

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接口。

我希望避免手动读取值,但考虑到我可能会选择这条路线,我认为这里已经回答了:可能重复