By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,187 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,187 IT Pros & Developers. It's quick & easy.

FileInfo doesn't expose FileType

P: n/a
I found FileInfo expose alot of methods & properties.
However I can't get FileType from FileInfo I can only get File extension.

How can I get fileType any build-in library allow me to do that?
If not please advice on what is the best way to get file type.

Many thanks,
kids
Nov 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
> However I can't get FileType from FileInfo I can only get File extension
What is file type? Did you mean that you want to detect if the file is
a text file or binary file?

Nov 23 '05 #2

P: n/a
Hi,

The name and extension of a file is your best guess to it contents without
actually reading the file itself. There is a little bit more information to
be found in the file version (see System.Diagnostics.FileVersionInfo)......

A jpg, bmp, gif are images...dll are libraries.....some are text and some
are binary.....

What exactly are you after?

Dave

"kids_pro" <ki******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found FileInfo expose alot of methods & properties.
However I can't get FileType from FileInfo I can only get File extension.

How can I get fileType any build-in library allow me to do that?
If not please advice on what is the best way to get file type.

Many thanks,
kids

Nov 23 '05 #3

P: n/a
Truong Hong Thi wrote:
However I can't get FileType from FileInfo I can only get File extension


What is file type? Did you mean that you want to detect if the file is
a text file or binary file?

No, for example you open My Document folder.
Change view to detail you will see column Type which tell you what is
the type of the file such as Text Document, WinZip File, Microsoft Word
Document etc.

Thanks,
kids
Nov 23 '05 #4

P: n/a
That information is registered in Windows Registry. As far as I know,
..NET does not provide a function to obtain this info. You may need to
call windows shell API: SHGetFileInfo, using platform invoke (e.i.
DllImportAttribute). More about SHGetFileInfo, see MSDN.

Thi

Nov 23 '05 #5

P: n/a
"kids_pro" <ki******@yahoo.com> wrote in message
news:Od**************@TK2MSFTNGP10.phx.gbl...
Truong Hong Thi wrote:
However I can't get FileType from FileInfo I can only get File extension


What is file type? Did you mean that you want to detect if the file is
a text file or binary file?

No, for example you open My Document folder.
Change view to detail you will see column Type which tell you what is the
type of the file such as Text Document, WinZip File, Microsoft Word
Document etc.

Thanks,
kids


Here's what I did a while back...
This article will help you:
http://msdn.microsoft.com/library/de...file_types.asp

What you are looking at is essentially registered types with an associated
application. Note that although all file extensions are registered, they may
or may not have an associated application. Also, while there is a standard
for writing this information to the registry, not all application
programmers follow the standard. You will see this as you investigate the
registry.

For the basic file type: for a given file extension, read the (Default)
value of the key with the same name in the HK_Classes_Root registry. Now
read the (Default) value of the key with that name from the HK_Classes_Root
registry.

extension: .doc
HK_CLASSES_ROOT
(Default) REG_SZ Word.Document.8
HK_CLASSES_ROOT\Word.Document.8
(Default) REG_SZ Microsoft Word Document

extension: .ini
HK_CLASSES_ROOT\.ini
(Default) REG_SZ inifile
HK_CLASSES_ROOT\infile
(Default) REG_SZ Setup Information

extension: .zip
HK_CLASSES_ROOT\.zip
(Default) REG_SZ CompressedFile
HK_CLASSES_ROOT\CompressedFile
(Default) REG_SZ Compressed (zipped) Folder

Refer to the MSDN article for further information on discovering the
associated application.

Hope this helps,
-Jeff
Nov 23 '05 #6

P: n/a
It's 1:30am, I'm tired and so there were some problems with my previous
response a few minutes ago. Hopefully this is better...

Here's what I did awhile back...
This article will help you:
http://msdn.microsoft.com/library/de...file_types.asp What you are looking at is essentially registered file extensions with anassociated application and file type information. Note that although allfile extensions are registered, they may or may not have an associatedapplication. Also, while there is a standard for writing this information to the registry, not all applicationprogrammers follow the standard. You will see this as you investigate theregistry. For the basic file type...For a given file extension, read the HK_Classes_Root registry the (Default)value of the key with the same name as the file extension. Now read fromthe HK_Classes_Root registry the (Default) value of the key with the samename as the previously read value. This will be your file type description. extension: .doc HK_CLASSES_ROOT\.doc (Default) REG_SZ Word.Document.8 HK_CLASSES_ROOT\Word.Document.8 (Default) REG_SZ Microsoft Word Document extension: .ini HK_CLASSES_ROOT\.ini (Default) REG_SZ inifile HK_CLASSES_ROOT\infile (Default) REG_SZ Setup Information extension: .zip HK_CLASSES_ROOT\.zip (Default) REG_SZ CompressedFile HK_CLASSES_ROOT\CompressedFile (Default) REG_SZ Compressed (zipped) Folder Refer to the MSDN article for further information on determining theassociated application. Hope this helps, -Jeff

Nov 23 '05 #7

P: n/a
You may want to add some error checking & stuff, but this is the
essentce of it:

using Microsoft.Win32;

string ext = ".doc";

RegistryKey key = Registry.ClassesRoot.OpenSubKey(ext);
string type = key.GetValue("") as string;
key = Registry.ClassesRoot.OpenSubKey(type);
string desc = key.GetValue("") as string;

Console.WriteLine(desc);

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"kids_pro" <ki******@yahoo.com> wrote in message
news:#C**************@TK2MSFTNGP12.phx.gbl...
I found FileInfo expose alot of methods & properties.
However I can't get FileType from FileInfo I can only get File extension.

How can I get fileType any build-in library allow me to do that?
If not please advice on what is the best way to get file type.

Many thanks,
kids

Nov 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.