2 using Microsoft.Win32.SafeHandles;
16 private const int GetFileExInfoStandard = 0;
18 private const int ERROR_INVALID_PARAMETER = 87;
20 private const int ERROR_ACCESS_DENIED = 5;
103 public static void Copy(
string sourceFileName,
string destFileName)
105 if (sourceFileName ==
null)
109 if (destFileName ==
null)
113 if (sourceFileName.Length == 0)
117 if (destFileName.Length == 0)
121 InternalCopy(sourceFileName, destFileName, overwrite:
false, checkHost:
true);
144 public static void Copy(
string sourceFileName,
string destFileName,
bool overwrite)
146 if (sourceFileName ==
null)
150 if (destFileName ==
null)
154 if (sourceFileName.Length == 0)
158 if (destFileName.Length == 0)
162 InternalCopy(sourceFileName, destFileName, overwrite, checkHost:
true);
166 internal static void UnsafeCopy(
string sourceFileName,
string destFileName,
bool overwrite)
168 if (sourceFileName ==
null)
172 if (destFileName ==
null)
176 if (sourceFileName.Length == 0)
178 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"sourceFileName");
180 if (destFileName.Length == 0)
182 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"destFileName");
184 InternalCopy(sourceFileName, destFileName, overwrite, checkHost:
false);
187 [SecuritySafeCritical]
188 internal static string InternalCopy(
string sourceFileName,
string destFileName,
bool overwrite,
bool checkHost)
190 string fullPathInternal =
Path.GetFullPathInternal(sourceFileName);
191 string fullPathInternal2 =
Path.GetFullPathInternal(destFileName);
194 if (!Win32Native.CopyFile(fullPathInternal, fullPathInternal2, !overwrite))
197 string maybeFullPath = destFileName;
198 if (lastWin32Error != 80)
200 using (SafeFileHandle safeFileHandle = Win32Native.UnsafeCreateFile(fullPathInternal,
int.MinValue,
FileShare.Read,
null,
FileMode.Open, 0, IntPtr.Zero))
202 if (safeFileHandle.IsInvalid)
204 maybeFullPath = sourceFileName;
207 if (lastWin32Error == 5 &&
Directory.InternalExists(fullPathInternal2))
209 throw new IOException(Environment.GetResourceString(
"Arg_FileIsDirectory_Name", destFileName), 5, fullPathInternal2);
212 __Error.WinIOError(lastWin32Error, maybeFullPath);
214 return fullPathInternal2;
233 return Create(path, 4096);
323 [SecuritySafeCritical]
330 InternalDelete(path, checkHost:
true);
334 internal static void UnsafeDelete(
string path)
340 InternalDelete(path, checkHost:
false);
344 internal static void InternalDelete(
string path,
bool checkHost)
346 string fullPathInternal = Path.GetFullPathInternal(path);
348 if (!Win32Native.DeleteFile(fullPathInternal))
351 if (lastWin32Error != 2)
353 __Error.WinIOError(lastWin32Error, fullPathInternal);
369 [SecuritySafeCritical]
376 string fullPathInternal =
Path.GetFullPathInternal(path);
378 if (Win32Native.DecryptFile(fullPathInternal, 0))
383 if (lastWin32Error == 5)
391 __Error.WinIOError(lastWin32Error, fullPathInternal);
405 [SecuritySafeCritical]
412 string fullPathInternal =
Path.GetFullPathInternal(path);
414 if (Win32Native.EncryptFile(fullPathInternal))
419 if (lastWin32Error == 5)
427 __Error.WinIOError(lastWin32Error, fullPathInternal);
434 [SecuritySafeCritical]
437 return InternalExistsHelper(path, checkHost:
true);
441 internal static bool UnsafeExists(
string path)
443 return InternalExistsHelper(path, checkHost:
false);
447 private static bool InternalExistsHelper(
string path,
bool checkHost)
455 if (path.Length == 0)
459 path =
Path.GetFullPathInternal(path);
460 if (path.Length > 0 &&
Path.IsDirectorySeparator(path[path.Length - 1]))
465 return InternalExists(path);
467 catch (ArgumentException)
470 catch (NotSupportedException)
479 catch (UnauthorizedAccessException)
486 internal static bool InternalExists(
string path)
488 Win32Native.WIN32_FILE_ATTRIBUTE_DATA data =
default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
489 if (FillAttributeInfo(path, ref data, tryagain:
false, returnErrorOnNotFound:
true) == 0 && data.fileAttributes != -1)
491 return (data.fileAttributes & 0x10) == 0;
573 return new FileStream(path, mode, access, share);
611 [SecuritySafeCritical]
614 SafeFileHandle handle;
615 using (OpenFile(path,
FileAccess.Write, out handle))
617 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(creationTimeUtc.
ToFileTimeUtc());
618 if (!Win32Native.SetFileTime(handle, &fILE_TIME,
null,
null))
621 __Error.WinIOError(lastWin32Error, path);
637 [SecuritySafeCritical]
640 return InternalGetCreationTimeUtc(path, checkHost:
true).
ToLocalTime();
654 [SecuritySafeCritical]
657 return InternalGetCreationTimeUtc(path, checkHost:
false);
661 private static DateTime InternalGetCreationTimeUtc(
string path,
bool checkHost)
663 string fullPathInternal =
Path.GetFullPathInternal(path);
665 Win32Native.WIN32_FILE_ATTRIBUTE_DATA data =
default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
666 int num = FillAttributeInfo(fullPathInternal, ref data, tryagain:
false, returnErrorOnNotFound:
false);
669 __Error.WinIOError(num, fullPathInternal);
671 long fileTime = (long)(((ulong)data.ftCreationTimeHigh << 32) | data.ftCreationTimeLow);
708 [SecuritySafeCritical]
711 SafeFileHandle handle;
712 using (OpenFile(path,
FileAccess.Write, out handle))
714 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(lastAccessTimeUtc.
ToFileTimeUtc());
715 if (!Win32Native.SetFileTime(handle,
null, &fILE_TIME,
null))
718 __Error.WinIOError(lastWin32Error, path);
734 [SecuritySafeCritical]
737 return InternalGetLastAccessTimeUtc(path, checkHost:
true).
ToLocalTime();
751 [SecuritySafeCritical]
754 return InternalGetLastAccessTimeUtc(path, checkHost:
false);
758 private static DateTime InternalGetLastAccessTimeUtc(
string path,
bool checkHost)
760 string fullPathInternal =
Path.GetFullPathInternal(path);
762 Win32Native.WIN32_FILE_ATTRIBUTE_DATA data =
default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
763 int num = FillAttributeInfo(fullPathInternal, ref data, tryagain:
false, returnErrorOnNotFound:
false);
766 __Error.WinIOError(num, fullPathInternal);
768 long fileTime = (long)(((ulong)data.ftLastAccessTimeHigh << 32) | data.ftLastAccessTimeLow);
805 [SecuritySafeCritical]
808 SafeFileHandle handle;
809 using (OpenFile(path,
FileAccess.Write, out handle))
811 Win32Native.FILE_TIME fILE_TIME =
new Win32Native.FILE_TIME(lastWriteTimeUtc.
ToFileTimeUtc());
812 if (!Win32Native.SetFileTime(handle,
null,
null, &fILE_TIME))
815 __Error.WinIOError(lastWin32Error, path);
831 [SecuritySafeCritical]
834 return InternalGetLastWriteTimeUtc(path, checkHost:
true).
ToLocalTime();
848 [SecuritySafeCritical]
851 return InternalGetLastWriteTimeUtc(path, checkHost:
false);
855 private static DateTime InternalGetLastWriteTimeUtc(
string path,
bool checkHost)
857 string fullPathInternal =
Path.GetFullPathInternal(path);
859 Win32Native.WIN32_FILE_ATTRIBUTE_DATA data =
default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
860 int num = FillAttributeInfo(fullPathInternal, ref data, tryagain:
false, returnErrorOnNotFound:
false);
863 __Error.WinIOError(num, fullPathInternal);
865 long fileTime = (long)(((ulong)data.ftLastWriteTimeHigh << 32) | data.ftLastWriteTimeLow);
883 [SecuritySafeCritical]
886 string fullPathInternal =
Path.GetFullPathInternal(path);
888 Win32Native.WIN32_FILE_ATTRIBUTE_DATA data =
default(Win32Native.WIN32_FILE_ATTRIBUTE_DATA);
889 int num = FillAttributeInfo(fullPathInternal, ref data, tryagain:
false, returnErrorOnNotFound:
true);
892 __Error.WinIOError(num, fullPathInternal);
910 [SecuritySafeCritical]
913 string fullPathInternal =
Path.GetFullPathInternal(path);
915 if (!Win32Native.SetFileAttributes(fullPathInternal, (
int)fileAttributes))
918 if (lastWin32Error == 87)
922 __Error.WinIOError(lastWin32Error, fullPathInternal);
959 [SecuritySafeCritical]
962 if (fileSecurity ==
null)
966 string fullPathInternal =
Path.GetFullPathInternal(path);
967 fileSecurity.
Persist(fullPathInternal);
1025 [SecuritySafeCritical]
1032 if (path.Length == 0)
1036 return InternalReadAllText(path,
Encoding.
UTF8, checkHost:
true);
1057 [SecuritySafeCritical]
1064 if (encoding ==
null)
1068 if (path.Length == 0)
1072 return InternalReadAllText(path, encoding, checkHost:
true);
1076 internal static string UnsafeReadAllText(
string path)
1082 if (path.Length == 0)
1086 return InternalReadAllText(path,
Encoding.
UTF8, checkHost:
false);
1090 private static string InternalReadAllText(
string path,
Encoding encoding,
bool checkHost)
1092 using (StreamReader streamReader =
new StreamReader(path, encoding, detectEncodingFromByteOrderMarks:
true, StreamReader.DefaultBufferSize, checkHost))
1094 return streamReader.ReadToEnd();
1114 [SecuritySafeCritical]
1121 if (path.Length == 0)
1125 InternalWriteAllText(path, contents,
StreamWriter.UTF8NoBOM, checkHost:
true);
1145 [SecuritySafeCritical]
1152 if (encoding ==
null)
1156 if (path.Length == 0)
1160 InternalWriteAllText(path, contents, encoding, checkHost:
true);
1164 internal static void UnsafeWriteAllText(
string path,
string contents)
1170 if (path.Length == 0)
1174 InternalWriteAllText(path, contents, StreamWriter.UTF8NoBOM, checkHost:
false);
1178 private static void InternalWriteAllText(
string path,
string contents,
Encoding encoding,
bool checkHost)
1180 using (StreamWriter streamWriter =
new StreamWriter(path, append:
false, encoding, 1024, checkHost))
1182 streamWriter.Write(contents);
1202 [SecuritySafeCritical]
1205 return InternalReadAllBytes(path, checkHost:
true);
1209 internal static byte[] UnsafeReadAllBytes(
string path)
1211 return InternalReadAllBytes(path, checkHost:
false);
1215 private static byte[] InternalReadAllBytes(
string path,
bool checkHost)
1220 long length = fileStream.Length;
1221 if (length >
int.MaxValue)
1223 throw new IOException(
Environment.GetResourceString(
"IO.IO_FileTooLong2GB"));
1225 int num2 = (int)length;
1226 byte[] array =
new byte[num2];
1229 int num3 = fileStream.Read(array, num, num2);
1232 __Error.EndOfFile();
1257 [SecuritySafeCritical]
1264 if (path.Length == 0)
1272 InternalWriteAllBytes(path, bytes, checkHost:
true);
1276 internal static void UnsafeWriteAllBytes(
string path,
byte[] bytes)
1282 if (path.Length == 0)
1288 throw new ArgumentNullException(
"bytes");
1290 InternalWriteAllBytes(path, bytes, checkHost:
false);
1294 private static void InternalWriteAllBytes(
string path,
byte[] bytes,
bool checkHost)
1298 fileStream.Write(bytes, 0, bytes.Length);
1325 if (path.Length == 0)
1356 if (encoding ==
null)
1360 if (path.Length == 0)
1364 return InternalReadAllLines(path, encoding);
1367 private static string[] InternalReadAllLines(
string path,
Encoding encoding)
1373 while ((item = streamReader.
ReadLine()) !=
null)
1378 return list.ToArray();
1404 if (path.Length == 0)
1408 return ReadLinesIterator.CreateIterator(path,
Encoding.
UTF8);
1435 if (encoding ==
null)
1439 if (path.Length == 0)
1443 return ReadLinesIterator.CreateIterator(path, encoding);
1467 if (contents ==
null)
1471 if (path.Length == 0)
1500 if (contents ==
null)
1504 if (encoding ==
null)
1508 if (path.Length == 0)
1512 InternalWriteAllLines(
new StreamWriter(path, append:
false, encoding), contents);
1538 if (contents ==
null)
1542 if (path.Length == 0)
1573 if (contents ==
null)
1577 if (encoding ==
null)
1581 if (path.Length == 0)
1585 InternalWriteAllLines(
new StreamWriter(path, append:
false, encoding), contents);
1592 foreach (
string content
in contents)
1621 if (path.Length == 0)
1625 InternalAppendAllText(path, contents,
StreamWriter.UTF8NoBOM);
1651 if (encoding ==
null)
1655 if (path.Length == 0)
1659 InternalAppendAllText(path, contents, encoding);
1662 private static void InternalAppendAllText(
string path,
string contents,
Encoding encoding)
1666 streamWriter.
Write(contents);
1694 if (contents ==
null)
1698 if (path.Length == 0)
1730 if (contents ==
null)
1734 if (encoding ==
null)
1738 if (path.Length == 0)
1742 InternalWriteAllLines(
new StreamWriter(path, append:
true, encoding), contents);
1759 [SecuritySafeCritical]
1760 public static void Move(
string sourceFileName,
string destFileName)
1762 InternalMove(sourceFileName, destFileName, checkHost:
true);
1766 internal static void UnsafeMove(
string sourceFileName,
string destFileName)
1768 InternalMove(sourceFileName, destFileName, checkHost:
false);
1772 private static void InternalMove(
string sourceFileName,
string destFileName,
bool checkHost)
1774 if (sourceFileName ==
null)
1778 if (destFileName ==
null)
1780 throw new ArgumentNullException(
"destFileName", Environment.GetResourceString(
"ArgumentNull_FileName"));
1782 if (sourceFileName.Length == 0)
1784 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"sourceFileName");
1786 if (destFileName.Length == 0)
1788 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"destFileName");
1790 string fullPathInternal =
Path.GetFullPathInternal(sourceFileName);
1791 string fullPathInternal2 =
Path.GetFullPathInternal(destFileName);
1794 if (!InternalExists(fullPathInternal))
1796 __Error.WinIOError(2, fullPathInternal);
1798 if (!Win32Native.MoveFile(fullPathInternal, fullPathInternal2))
1800 __Error.WinIOError();
1816 public static void Replace(
string sourceFileName,
string destinationFileName,
string destinationBackupFileName)
1818 if (sourceFileName ==
null)
1822 if (destinationFileName ==
null)
1826 InternalReplace(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors:
false);
1843 public static void Replace(
string sourceFileName,
string destinationFileName,
string destinationBackupFileName,
bool ignoreMetadataErrors)
1845 if (sourceFileName ==
null)
1849 if (destinationFileName ==
null)
1853 InternalReplace(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors);
1856 [SecuritySafeCritical]
1857 private static void InternalReplace(
string sourceFileName,
string destinationFileName,
string destinationBackupFileName,
bool ignoreMetadataErrors)
1859 string fullPathInternal =
Path.GetFullPathInternal(sourceFileName);
1860 string fullPathInternal2 =
Path.GetFullPathInternal(destinationFileName);
1862 if (destinationBackupFileName !=
null)
1864 text =
Path.GetFullPathInternal(destinationBackupFileName);
1866 if (CodeAccessSecurityEngine.QuickCheckForAllDemands())
1886 fileIOPermission.
Demand();
1889 if (ignoreMetadataErrors)
1893 if (!Win32Native.ReplaceFile(fullPathInternal2, fullPathInternal, text, num, IntPtr.Zero, IntPtr.Zero))
1895 __Error.WinIOError();
1900 internal static int FillAttributeInfo(
string path, ref Win32Native.WIN32_FILE_ATTRIBUTE_DATA data,
bool tryagain,
bool returnErrorOnNotFound)
1905 Win32Native.WIN32_FIND_DATA wIN32_FIND_DATA =
new Win32Native.WIN32_FIND_DATA();
1906 string fileName = path.TrimEnd(
Path.DirectorySeparatorChar,
Path.AltDirectorySeparatorChar);
1907 int errorMode = Win32Native.SetErrorMode(1);
1911 SafeFindHandle safeFindHandle = Win32Native.FindFirstFile(fileName, wIN32_FIND_DATA);
1914 if (safeFindHandle.IsInvalid)
1918 if ((num == 2 || num == 3 || num == 21) && !returnErrorOnNotFound)
1921 data.fileAttributes = -1;
1930 safeFindHandle.Close();
1936 __Error.WinIOError();
1943 Win32Native.SetErrorMode(errorMode);
1945 data.PopulateFrom(wIN32_FIND_DATA);
1950 int errorMode2 = Win32Native.SetErrorMode(1);
1953 flag2 = Win32Native.GetFileAttributesEx(path, 0, ref data);
1957 Win32Native.SetErrorMode(errorMode2);
1962 if (num != 2 && num != 3 && num != 21)
1964 return FillAttributeInfo(path, ref data, tryagain:
true, returnErrorOnNotFound);
1966 if (!returnErrorOnNotFound)
1969 data.fileAttributes = -1;
1977 private static FileStream OpenFile(
string path,
FileAccess access, out SafeFileHandle handle)
1979 FileStream fileStream =
new FileStream(path,
FileMode.Open, access,
FileShare.ReadWrite, 1);
1980 handle = fileStream.SafeFileHandle;
1981 if (handle.IsInvalid)
1984 string fullPathInternal =
Path.GetFullPathInternal(path);
1985 if (num == 3 && fullPathInternal.Equals(
Directory.GetDirectoryRoot(fullPathInternal)))
1989 __Error.WinIOError(num, path);
Represents a character encoding.To browse the .NET Framework source code for this type,...
FileSystemRights
Defines the access rights to use when creating access and audit rules.
static DateTime GetCreationTime(string path)
Returns the creation date and time of the specified file or directory.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static void SetAttributes(string path, FileAttributes fileAttributes)
Sets the specified T:System.IO.FileAttributes of the file on the specified path.
FileIOPermissionAccess
Specifies the type of file access requested.
static bool Exists(string path)
Determines whether the specified file exists.
static FileSecurity GetAccessControl(string path, AccessControlSections includeSections)
Gets a T:System.Security.AccessControl.FileSecurity object that encapsulates the specified type of ac...
static StreamWriter CreateText(string path)
Creates or opens a file for writing UTF-8 encoded text.
FileOptions
Represents advanced options for creating a T:System.IO.FileStream object.
static string ReadAllText(string path, Encoding encoding)
Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
static FileStream Create(string path)
Creates or overwrites a file in the specified path.
static void WriteAllText(string path, string contents, Encoding encoding)
Creates a new file, writes the specified string to the file using the specified encoding,...
long ToFileTimeUtc()
Converts the value of the current T:System.DateTime object to a Windows file time.
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.
static unsafe void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
Sets the date and time, in coordinated universal time (UTC), that the specified file was last written...
Represents the access control and audit security for a file. This class cannot be inherited.
FileAttributes
Provides attributes for files and directories.
static void AppendAllText(string path, string contents, Encoding encoding)
Appends the specified string to the file, creating the file if it does not already exist.
static FileStream OpenWrite(string path)
Opens an existing file or creates a new file for writing.
static string GetPathRoot(string path)
Gets the root directory information of the specified path.
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
static FileStream Create(string path, int bufferSize)
Creates or overwrites the specified file.
static FileStream OpenRead(string path)
Opens an existing file for reading.
static DateTime GetLastWriteTime(string path)
Returns the date and time the specified file or directory was last written to.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
static IEnumerable< string > ReadLines(string path, Encoding encoding)
Read the lines of a file that has a specified encoding.
override string ReadLine()
Reads a line of characters from the current stream and returns the data as a string.
static string [] ReadAllLines(string path, Encoding encoding)
Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
static DateTime GetCreationTimeUtc(string path)
Returns the creation date and time, in coordinated universal time (UTC), of the specified file or dir...
static void SetCreationTime(string path, DateTime creationTime)
Sets the date and time the file was created.
static DateTime GetLastAccessTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
static FileSecurity GetAccessControl(string path)
Gets a T:System.Security.AccessControl.FileSecurity object that encapsulates the access control list ...
static DateTime FromFileTimeUtc(long fileTime)
Converts the specified Windows file time to an equivalent UTC time.
DateTime ToLocalTime()
Converts the value of the current T:System.DateTime object to local time.
static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
Replaces the contents of a specified file with the contents of another file, deleting the original fi...
static void WriteAllLines(string path, string[] contents)
Creates a new file, write the specified string array to the file, and then closes the file.
static FileStream Create(string path, int bufferSize, FileOptions options, FileSecurity fileSecurity)
Creates or overwrites the specified file with the specified buffer size, file options,...
static void SetAccessControl(string path, FileSecurity fileSecurity)
Applies access control list (ACL) entries described by a T:System.Security.AccessControl....
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....
void AddPathList(FileIOPermissionAccess access, string path)
Adds access for the specified file or directory to the existing state of the permission.
static unsafe void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
Sets the date and time, in coordinated universal time (UTC), that the file was created.
static StreamWriter AppendText(string path)
Creates a T:System.IO.StreamWriter that appends UTF-8 encoded text to an existing file,...
sealed override void Persist(string name, AccessControlSections includeSections)
Saves the specified sections of the security descriptor associated with this T:System....
static void WriteAllLines(string path, IEnumerable< string > contents, Encoding encoding)
Creates a new file by using the specified encoding, writes a collection of strings to the file,...
static void WriteAllLines(string path, IEnumerable< string > contents)
Creates a new file, writes a collection of strings to the file, and then closes the file.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
static FileStream Open(string path, FileMode mode)
Opens a T:System.IO.FileStream on the specified path with read/write access.
static void Copy(string sourceFileName, string destFileName, bool overwrite)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
Represents a writer that can write a sequential series of characters. This class is abstract.
static void Copy(string sourceFileName, string destFileName)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
static void WriteAllText(string path, string contents)
Creates a new file, writes the specified string to the file, and then closes the file....
static void AppendAllText(string path, string contents)
Opens a file, appends the specified string to the file, and then closes the file. If the file does no...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
Opens a T:System.IO.FileStream on the specified path, having the specified mode with read,...
Provides access to information on a drive.
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...
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static void AppendAllLines(string path, IEnumerable< string > contents, Encoding encoding)
Appends lines to a file by using a specified encoding, and then closes the file. If the specified fil...
override void Write(char value)
Writes a character to the stream.
FileAccess
Defines constants for read, write, or read/write access to a file.
static FileAttributes GetAttributes(string path)
Gets the T:System.IO.FileAttributes of the file on the path.
static DateTime GetLastWriteTimeUtc(string path)
Returns the date and time, in coordinated universal time (UTC), that the specified file or directory ...
virtual void WriteLine()
Writes a line terminator to the text string or stream.
static void WriteAllLines(string path, string[] contents, Encoding encoding)
Creates a new file, writes the specified string array to the file by using the specified encoding,...
static Encoding UTF8
Gets an encoding for the UTF-8 format.
string DriveFormat
Gets the name of the file system, such as NTFS or FAT32.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
static void SetLastWriteTime(string path, DateTime lastWriteTime)
Sets the date and time that the specified file was last written to.
static void Move(string sourceFileName, string destFileName)
Moves a specified file to a new location, providing the option to specify a new file name.
static IEnumerable< string > ReadLines(string path)
Reads the lines of a file.
static void Decrypt(string path)
Decrypts a file that was encrypted by the current account using the M:System.IO.File....
static void Delete(string path)
Deletes the specified file.
static StreamReader OpenText(string path)
Opens an existing UTF-8 encoded text file for reading.
static string [] ReadAllLines(string path)
Opens a text file, reads all lines of the file, and then closes the file.
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Controls the ability to access files and folders. This class cannot be inherited.
static FileStream Create(string path, int bufferSize, FileOptions options)
Creates or overwrites the specified file, specifying a buffer size and a T:System....
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
DateTime ToUniversalTime()
Converts the value of the current T:System.DateTime object to Coordinated Universal Time (UTC).
static string ReadAllText(string path)
Opens a text file, reads all lines of the file, and then closes the file.
static void SetLastAccessTime(string path, DateTime lastAccessTime)
Sets the date and time the specified file was last accessed.
static byte [] ReadAllBytes(string path)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
static unsafe void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
Sets the date and time, in coordinated universal time (UTC), that the specified file was last accesse...
static FileStream Open(string path, FileMode mode, FileAccess access)
Opens a T:System.IO.FileStream on the specified path, with the specified mode and access.
AccessControlSections
Specifies which sections of a security descriptor to save or load.
The P:System.Uri.LocalPath data.
The exception that is thrown when a security error is detected.
Performs operations on T:System.String instances that contain file or directory path information....
static DateTime GetLastAccessTime(string path)
Returns the date and time the specified file or directory was last accessed.
static void WriteAllBytes(string path, byte[] bytes)
Creates a new file, writes the specified byte array to the file, and then closes the file....
FileShare
Contains constants for controlling the kind of access other T:System.IO.FileStream objects can have t...
static void AppendAllLines(string path, IEnumerable< string > contents)
Appends lines to a file, and then closes the file. If the specified file does not exist,...