Is there an easy way to determine what a file is by its extension in C#? -


Is there an easy way to determine what files are in detail in C #? For example, if I pass the ".txt" file extension then it will return "text document" or if I pass it ".pdf" then it will return "Adobe Acrobat Reader". I see this behavior created in Windows Explorer under the "Type" column. Is there any way to copy it in C #?

If you really want to get an explorer and you are ready to use Com Interop , You can use the shell. To get the application class with the minimum amount of code. If you go to add a reference, then browse to X: \ windows \ system32 \ shell32.dll which will import Shell 32 type library. Then just use the code:

 string GetFileType (string path) {Shell32.ShellClass shell = new Shell32.SheClCl (); Shell32.Folder folder = shellNameSpace (path.getDirectoryName (path)); Shell32.FolderItem item = folder. Purpose (path. GetFileName (path)); Return folder. GetDetailsOf (item, 2); } 

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -