473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

FileInfo doesn't expose FileType

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
7 8319
> 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
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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
7
by: John R. | last post by:
How do you set the following file attributes: Compressed Encrypted Normal ReparsePoint SparsePoint You CAN'T set these using FileInfo.Attributes or File.SetAttributes. It doesn't work for...
2
by: todd | last post by:
Hi all. I inherited this code from a contractor. It is a .NET user control that runs on the client side (ie) on machines with the framework installed. I have been mucking around to get it work...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
5
by: mike | last post by:
Hi, I have been playing with VB.NET/C# for getting some general properties of a fileinfo object. However, FileInfo object does not seem to expose some of the basic properties like TYPE that used...
1
by: Michael A. Covington | last post by:
I just saw something like this in someone else's code and am curious... string fname; .... store a filename in fn ... FileInfo fi = new FileInfo(fname); string name = fi.Name;
3
by: rn5a | last post by:
To work with files, when should one use the File class & when should one use the FileInfo class? Similarly, to work with directories, when should one use the Directory class & when should one...
63
by: David Mathog | last post by:
There have been a series of questions about directory operations, all of which have been answered with "there is no portable way to do this". This raises the perfectly reasonable question, why,...
6
by: tshad | last post by:
Can't use FileInfo in using statement? I have the following statement: using (FileInfo fInfo = new FileInfo(fromImagePath + "\\" + (string)dr)) and I get the following error: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.