2009-10-17 4 views
0

클래식 ASP에서 우리는 File.Type 속성을 사용하여 레지스트리의 파일 유형과 연결된 이름을 가져 왔습니다 (예 : ".txt"의 경우 "Text Document"). 일반적으로 이전 COM 개체를 대체하는 FileInfo 클래스는이 기능을 복제하지 않으며 지금까지 대체 검색에 대한 검색에서 많은 성공을 거두지 못했습니다.File.Type FileSystemObject 속성에 대한 .NET 대체품은 무엇입니까?

+0

가능한 복제본 http://stackoverflow.com/questions/1437382/get-file-type-in-net – Helen

+0

나는 그것이 여기에 대답했다고 생각 : http://stackoverflow.com/questions/1437382/get- file-type-in-c –

답변

1

본인은 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); 

    } 
} 

그러나, 블라디미르에서 제공하는 link에 사용되는 방법이으로 선호된다 API 인터페이스를 사용합니다.

+0

값을 수동으로 읽지 않기를 바랬지 만이 경로를 선택할 수있는 옵션이 주어졌습니다. –

관련 문제