Is there an easy way to determine which file is its extension in C #?

Is there an easy way to determine which file is its extension in C #? For example, if I pass the file extension “.txt”, then it will return “Text document”, or if I pass it “.pdf”, it will return “Adobe Acrobat Reader”. I see this behavior embedded in Windows Explorer in the Type column. Is there any way to simulate this in C #?

+3
source share
4 answers

If you want to get what the researcher really shows, and are ready to use the COM operator, you can use the Shell.Application class to get it with a minimal amount of code. If you add the link, go to X: \ windows \ system32 \ shell32.dll, which will import the shell32 type library. Then just use the code:

string GetFileType (string path)
{
   Shell32.ShellClass shell = new Shell32.ShellClass ();
   Shell32.Folder folder = shell.NameSpace (Path.GetDirectoryName (path));

   Shell32.FolderItem item = folder.ParseName (Path.GetFileName (path));
   return folder.GetDetailsOf (item, 2);
}
+4
source

Use the registry class to query for an HKCR hive.

+1
source

;

-3

Source: https://habr.com/ru/post/1724804/


All Articles