Type of File  
Author Message
ajustin





PostPosted: .NET Framework Data Access and Storage, Type of File Top

Hi Guys,

How can I extract the information of a file like 'Type of File' ex.

Type of File: Microsoft Excel Worksheet. I am able to extract the other information

like Last Access..using FileInfo. But I can't find the value for the said subject.

Can you please give me a sample code 'coz I'm just new to Visual Basic 2005

Thanks in advance.



.NET Development15  
 
 
Lepaca





PostPosted: .NET Framework Data Access and Storage, Type of File Top

I am not sure, if I understood...

If you want the type of an object, you can use: <object>.gettype.tostring...
If you want the type of a file, you can read its extension with: IO.Path.GetExtension(<path>)

Examples...

Dim exc As New Excel.ApplicationClass
Debug.WriteLine(exc.GetType.ToString) ' -> "Excel.ApplicationClass"

Debug.WriteLine(IO.Path.GetExtension("C:\example.xls")) ' -> ".xls"


 
 
ajustin





PostPosted: .NET Framework Data Access and Storage, Type of File Top

Hi Lepaca,

Thanks for your support.

But what i really want to extract from a file is for ex.

Name Size Type Modifed

Cimage File Folder 04/12/2006 9:23

tdms.doc 94kb Microsoft Word Document 04/12/2006 9:12

the bold info is really the one I need to extract. other than that

I can extract the other info.

Thanks again


 
 
Lepaca





PostPosted: .NET Framework Data Access and Storage, Type of File Top

you can read description of an extension in registry...

this read folders description:
Microsoft.Win32.Registry.GetValue("HKEY_CLASSES_ROOT\Directory", "", "").ToString

this read all files in a folder and give its description:
For Each doc As String In IO.Directory.GetFiles("Path")
Dim s As String = Microsoft.Win32.Registry.GetValue("HKEY_CLASSES_ROOT\" & IO.Path.GetExtension(doc), "", "").ToString
Debug.WriteLine(Microsoft.Win32.Registry.GetValue(
"HKEY_CLASSES_ROOT\" & s, "", "").ToString)
Next


 
 
ajustin





PostPosted: .NET Framework Data Access and Storage, Type of File Top

Hi Lepaca,

Thanks for the quick replies.

ok i'll try your sample code and get back to you.

thanks again


 
 
VMazur





PostPosted: .NET Framework Data Access and Storage, Type of File Top

You could use two ways. One is to check extention of the file. It is not reliable 10%, but could be enough for you. Another way is to analize first 4 bytes (I believe it is correct number) of the file, beccause usually binary-type files contain prefix codes at the beginning that help to check their type.