20 public override string Name => _name;
29 [SecuritySafeCritical]
32 if (_dataInitialised == -1)
36 if (_dataInitialised != 0)
38 __Error.WinIOError(_dataInitialised, base.DisplayPath);
40 if ((_data.fileAttributes & 0x10) != 0)
42 __Error.WinIOError(2, base.DisplayPath);
44 return ((
long)_data.fileSizeHigh << 32) | (_data.fileSizeLow & uint.MaxValue);
56 [SecuritySafeCritical]
60 if (directoryName !=
null)
77 if (directoryName ==
null)
114 public override bool Exists 116 [SecuritySafeCritical]
121 if (_dataInitialised == -1)
125 if (_dataInitialised != 0)
129 return (_data.fileAttributes & 0x10) == 0;
148 [SecuritySafeCritical]
151 if (fileName ==
null)
155 Init(fileName, checkHost:
true);
159 private void Init(
string fileName,
bool checkHost)
162 string fullPathInternal =
Path.GetFullPathInternal(fileName);
166 base.DisplayPath = GetDisplayPath(fileName);
169 private string GetDisplayPath(
string originalPath)
176 : base(info, context)
183 internal FileInfo(
string fullPath,
bool ignoreThis)
185 _name =
Path.GetFileName(fullPath);
188 base.DisplayPath = _name;
234 [SecuritySafeCritical]
273 if (destFileName ==
null)
277 if (destFileName.Length == 0)
281 destFileName =
File.InternalCopy(
FullPath, destFileName, overwrite:
false, checkHost:
true);
282 return new FileInfo(destFileName, ignoreThis:
false);
303 if (destFileName ==
null)
307 if (destFileName.Length == 0)
311 destFileName =
File.InternalCopy(
FullPath, destFileName, overwrite, checkHost:
true);
312 return new FileInfo(destFileName, ignoreThis:
false);
326 [SecuritySafeCritical]
330 if (!Win32Native.DeleteFile(
FullPath))
333 if (lastWin32Error != 2)
335 __Error.WinIOError(lastWin32Error, base.DisplayPath);
444 [SecuritySafeCritical]
447 if (destFileName ==
null)
451 if (destFileName.Length == 0)
455 string fullPathInternal =
Path.GetFullPathInternal(destFileName);
458 if (!Win32Native.MoveFile(
FullPath, fullPathInternal))
460 __Error.WinIOError();
465 base.DisplayPath = GetDisplayPath(destFileName);
466 _dataInitialised = -1;
480 return Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors:
false);
494 public FileInfo Replace(
string destinationFileName,
string destinationBackupFileName,
bool ignoreMetadataErrors)
496 File.
Replace(
FullPath, destinationFileName, destinationBackupFileName, ignoreMetadataErrors);
497 return new FileInfo(destinationFileName);
504 return base.DisplayPath;
Represents a character encoding.To browse the .NET Framework source code for this type,...
override string Name
Gets the name of the file.
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
FileIOPermissionAccess
Specifies the type of file access requested.
string DirectoryName
Gets a string representing the directory's full path.
static FileStream Create(string path)
Creates or overwrites a file in the specified path.
static void Encrypt(string path)
Encrypts a file so that only the account used to encrypt the file can decrypt it.
FileMode
Specifies how the operating system should open a file.
FileInfo(string fileName)
Initializes a new instance of the T:System.IO.FileInfo class, which acts as a wrapper for a file path...
Represents the access control and audit security for a file. This class cannot be inherited.
FileAttributes
Provides attributes for files and directories.
override void Delete()
Permanently deletes a file.
FileStream Open(FileMode mode, FileAccess access, FileShare share)
Opens a file in the specified mode with read, write, or read/write access and the specified sharing o...
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
void Encrypt()
Encrypts a file so that only the account used to encrypt the file can decrypt it.
void SetAccessControl(FileSecurity fileSecurity)
Applies access control list (ACL) entries described by a T:System.Security.AccessControl....
static string GetFileName(string path)
Returns the file name and extension of the specified path string.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
StreamReader OpenText()
Creates a T:System.IO.StreamReader with UTF8 encoding that reads from an existing text file.
static FileSecurity GetAccessControl(string path)
Gets a T:System.Security.AccessControl.FileSecurity object that encapsulates the access control list ...
void Decrypt()
Decrypts a file that was encrypted by the current account using the M:System.IO.FileInfo....
static void SetAccessControl(string path, FileSecurity fileSecurity)
Applies access control list (ACL) entries described by a T:System.Security.AccessControl....
FileStream Open(FileMode mode, FileAccess access)
Opens a file in the specified mode with read, write, or read/write access.
Implements a T:System.IO.TextWriter for writing characters to a stream in a particular encoding....
Provides information about, and means to manipulate, the current environment and platform....
Provides properties and instance methods for the creation, copying, deletion, moving,...
FileStream Open(FileMode mode)
Opens a file in the specified mode.
FileStream OpenWrite()
Creates a write-only T:System.IO.FileStream.
Exposes static methods for creating, moving, and enumerating through directories and subdirectories....
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
Replaces the contents of a specified file with the file described by the current T:System....
override string ToString()
Returns the path as a string.
FileInfo CopyTo(string destFileName)
Copies an existing file to a new file, disallowing the overwriting of an existing file.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
FileInfo CopyTo(string destFileName, bool overwrite)
Copies an existing file to a new file, allowing the overwriting of an existing file.
static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName)
Replaces the contents of a specified file with the contents of another file, deleting the original fi...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
FileSecurity GetAccessControl(AccessControlSections includeSections)
Gets a T:System.Security.AccessControl.FileSecurity object that encapsulates the specified type of ac...
FileStream Create()
Creates a file.
The exception that is thrown when one of the arguments provided to a method is not valid.
StreamWriter AppendText()
Creates a T:System.IO.StreamWriter that appends text to the file represented by this instance of the ...
FileSecurity GetAccessControl()
Gets a T:System.Security.AccessControl.FileSecurity object that encapsulates the access control list ...
FileAccess
Defines constants for read, write, or read/write access to a file.
FileInfo Replace(string destinationFileName, string destinationBackupFileName)
Replaces the contents of a specified file with the file described by the current T:System....
bool IsReadOnly
Gets or sets a value that determines if the current file is read only.
void Refresh()
Refreshes the state of the object.
StreamWriter CreateText()
Creates a T:System.IO.StreamWriter that writes a new text file.
Specifies that the class can be serialized.
static Encoding UTF8
Gets an encoding for the UTF-8 format.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
static void Decrypt(string path)
Decrypts a file that was encrypted by the current account using the M:System.IO.File....
static string GetDirectoryName(string path)
Returns the directory information for the specified path string.
Controls the ability to access files and folders. This class cannot be inherited.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
override bool Exists
Gets a value indicating whether a file exists.
Provides the base class for both T:System.IO.FileInfo and T:System.IO.DirectoryInfo objects.
string FullPath
Represents the fully qualified path of the directory or file.
AccessControlSections
Specifies which sections of a security descriptor to save or load.
The P:System.Uri.LocalPath data.
Performs operations on T:System.String instances that contain file or directory path information....
FileStream OpenRead()
Creates a read-only T:System.IO.FileStream.
void MoveTo(string destFileName)
Moves a specified file to a new location, providing the option to specify a new file name.
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
string OriginalPath
The path originally specified by the user, whether relative or absolute.
long Length
Gets the size, in bytes, of the current file.