Re: FileInfo, Getting File properties, particularly File TYPE

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Just to add a bit to this .. I would imagine the reason why it is not there
is that these are classes from the BCL which are supposed to be system
agnostic (see ECMA 335 partition 4). Since many other systems do not know
the concept of this description string it would not make alot of sense to
put it in.

Cheers,

Greg Young
MVP - C#
"smc750 via DotNetMonster.com" <u21663@uwe> wrote in message
news:6024efb680013@xxxxxx
A lot of this information is in the registry. For instance, the 'TYPE' you
refer to is set by the application that is associated. You can get the
file
type description via the following code. For example, if you pass in the
extension of .tif, based on what application is associated with the
extension,
it will return something like
"MSPaper.Document". Try the following code. You could create a class that
could encapsulate all the properties you want to get for a file via the
registry and then use this in your code to augment the fileInfo class.
Remember also that your code will need registry permissions to access the
registry which can be set via an attribute at the top of the class.

using System;
using Microsoft.Win32;


namespace CertDev
{

public class RegHelper
{
public RegHelper()
{}

public string GetFileType(string extension)
{

string contentType;

using(RegistryKey rgk = Registry.ClassesRoot.OpenSubKey("\\"+extension))
{

contentType = rgk.GetValue("",string.Empty).ToString();

}

return contentType;


}
}
}

smc750
www.certdev.com


mike wrote:
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 to be available in "FileSystemObject"
of
ScriptingLibrary. For example the "TYPE" property should return "Text
Document" or "Microsoft Office Document" or "Visual Studio Code File" and
so
on. similar to the properties displayed by Properties DialogBox when we
right-click and select Properties From Context-Menu in Windows Explorer.

I was able to get general properties like Modified date, attributes like
ReadOnly, Archieve, Hidden. but after spending hours I resorted to posting
this here.
Any help is greatly appreciated.
Thanks
--Mayur Hirpara

--
smc750
www.certdev.com

Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-general/200605/1


.



Relevant Pages

  • Re: Music Tasks not working
    ... Those string values already exist in the registry for mp3 files which is the ... It involves editing the registry, so ONLY TRY THIS IF YOU ... > add the appropriate audio file extension. ... Repeat these steps for each file type that is not working ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: FileInfo, Getting File properties, particularly File TYPE
    ... The new code now makes a second lookup into the registry. ... will only work if there is an application associated with the file extension. ... If there is not one it will return an empty string. ...
    (microsoft.public.dotnet.general)
  • Re: FileInfo, Getting File properties, particularly File TYPE
    ... extension of .tif, based on what application is associated with the extension, ... Remember also that your code will need registry permissions to access the ... FileInfo object does not seem to expose some of the ...
    (microsoft.public.dotnet.general)
  • Re: FileInfo, Getting File properties, particularly File TYPE
    ... A lot of this information is in the registry. ... extension of .tif, based on what application is associated with the extension, ... FileInfo object does not seem to expose some of the ... I was able to get general properties like Modified date, ...
    (microsoft.public.dotnet.general)
  • sample code for finding type of file based on extension
    ... Private Function GetNameForExtension(ByVal Extension As String) As String ... Dim s_tempName As String = String.Empty ... ' if we got a class name back from the registry for that extension, ...
    (microsoft.public.dotnet.languages.vb)