System.IO.FileSystemInfo Class

Assembly: Mscorlib.dll
Namespace: System.IO
Summary
Provides the base class for both FileInfo and DirectoryInfo objects.
C# Syntax:
[Serializable]
public abstract class FileSystemInfo : MarshalByRefObject
Remarks
The FileSystemInfo class contains methods that are common to file and directory manipulation. A FileSystemInfo object can represent either a file or a directory, thus serving as the basis for FileInfo or DirectoryInfo objects. Use this base class when parsing a lot of files and directories.

In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all of the following are acceptable paths:

See also:
System.IO Namespace

System.IO.FileSystemInfo Member List:

Public Properties
Attributes Read-write

Gets or sets the FileAttributes of the current FileSystemInfo.
CreationTime Read-write

Gets or sets the creation time of the current FileSystemInfo object.
Exists Read-only

Gets a value indicating whether the file or directory exists.
Extension Read-only

Gets the string representing the extension part of the file.
FullName Read-only

Gets the full path of the directory or file.
LastAccessTime Read-write

Gets or sets the time the current file or directory was last accessed.
LastWriteTime Read-write

Gets or sets the time when the current file or directory was last written to.
Name Read-only

For files, gets the name of the file. For directories, gets the name of the last directory in the hierarchy if a hierarchy exists. Otherwise, the Name property gets the name of the directory.
Public Methods
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Delete Deletes a file or directory.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
Refresh Refreshes the state of the object.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Protected Fields
FullPath Represents the fully qualified path of the directory or file.
OriginalPath The path originally specified by the user, whether relative or absolute.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.IO.FileSystemInfo Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected FileSystemInfo();

Return to top


Field: FullPath
Summary
Represents the fully qualified path of the directory or file.
C# Syntax:
protected string FullPath;
Remarks


Notes to inheritors: Classes derived from FileSystemInfo can use the FullPath field to determine the full path of the object being manipulated.

Return to top


Field: OriginalPath
Summary
The path originally specified by the user, whether relative or absolute.
C# Syntax:
protected string OriginalPath;

Return to top


Property: Attributes (read-write)
Summary
Gets or sets the FileAttributes of the current FileSystemInfo.
C# Syntax:
public FileAttributes Attributes {get; set;}
Exceptions
Exception Type Condition
FileNotFoundException The caller attempts to access a file that does not exist on disk.
SecurityException The caller does not have the required permission.
ArgumentException The caller attempts to set an invalid file attribute.
IOException FileSystemInfo.Refresh cannot initialize the data.
Remarks
The value of this property is a combination of the archive, compressed, directory, hidden, offline, read-only, system, and temporary file attribute flags.
.NET Framework Security:
FileIOPermissionAccess Write permission required to set the attributes for the specified file.

Return to top


Property: CreationTime (read-write)
Summary
Gets or sets the creation time of the current FileSystemInfo object.
C# Syntax:
public DateTime CreationTime {get; set;}
Exceptions
Exception Type Condition
IOException FileSystemInfo.Refresh cannot initialize the data.
FileNotFoundException The FileSystemInfo object does not exist.
Remarks
This property value is null if the file system containing the FileSystemInfo object does not support this information.

Return to top


Property: Exists (read-only)
Summary
Gets a value indicating whether the file or directory exists.
C# Syntax:
public abstract bool Exists {get;}

Return to top


Property: Extension (read-only)
Summary
Gets the string representing the extension part of the file.
C# Syntax:
public string Extension {get;}
Remarks
The Extension property returns the FileSystemInfo extension, including the period (.). For example, for a file c:\NewFile.txt, this property returns ".txt".

Return to top


Property: FullName (read-only)
Summary
Gets the full path of the directory or file.
C# Syntax:
public virtual string FullName {get;}
Remarks
For example, for a file c:\NewFile.txt, this property returns "NewFile.txt".
.NET Framework Security:
FileIOPermission for access to the path. Associated enumeration: FileIOPermissionAccess.PathDiscovery

Return to top


Property: LastAccessTime (read-write)
Summary
Gets or sets the time the current file or directory was last accessed.
C# Syntax:
public DateTime LastAccessTime {get; set;}
Exceptions
Exception Type Condition
IOException FileSystemInfo.Refresh cannot initialize the data.
Remarks
This property value is null if the file system containing the file does not support this information.

Return to top


Property: LastWriteTime (read-write)
Summary
Gets or sets the time when the current file or directory was last written to.
C# Syntax:
public DateTime LastWriteTime {get; set;}
Exceptions
Exception Type Condition
IOException FileSystemInfo.Refresh cannot initialize the data.
Remarks
This property value is null if the file system containing the file does not support this information.

Return to top


Property: Name (read-only)
Summary
For files, gets the name of the file. For directories, gets the name of the last directory in the hierarchy if a hierarchy exists. Otherwise, the Name property gets the name of the directory.
C# Syntax:
public abstract string Name {get;}
Remarks
For a directory, Name returns only the name of the parent directory, such as Dir, not c:\Dir. For a subdirectory, Name returns only the name of the subdirectory, such as Sub1, not c:\Dir\Sub1.

For a file, Name returns only the file name and file name extension, such as MyFile.txt, not c:\Dir\Myfile.txt.

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Method: Delete()
Summary
Deletes a file or directory.
C# Syntax:
public abstract void Delete();

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~FileSystemInfo();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Refresh()
Summary
Refreshes the state of the object.
C# Syntax:
public void Refresh();
Exceptions
Exception Type Condition
ArgumentException The file is not found.
IOException A device such as a disk drive is not ready.
Remarks
FileSystemInfo.Refresh takes a snapshot of the file from the current file system.Refresh cannot correct the underlying file system even if the file system returns incorrect or outdated information. This can happen on platforms such as Windows 98.

Calls must be made to Refresh before attempting to get the attribute information, or the information will be outdated.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.