Re: FileInfo, Getting File properties, particularly File TYPE
- From: "Greg Young" <DruckDruckGoose@xxxxxxxxxxx>
- Date: Fri, 12 May 2006 11:07:43 -0400
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
.
- References:
- Re: FileInfo, Getting File properties, particularly File TYPE
- From: smc750 via DotNetMonster.com
- Re: FileInfo, Getting File properties, particularly File TYPE
- Prev by Date: Re: FileInfo, Getting File properties, particularly File TYPE
- Next by Date: How to disable regions in Visual Studio?
- Previous by thread: Re: FileInfo, Getting File properties, particularly File TYPE
- Next by thread: Re: FileInfo, Getting File properties, particularly File TYPE
- Index(es):
Relevant Pages
|