Interface IFile
Provides methods for working with file.
Namespace: Terrasoft.IO
Assembly: Terrasoft.IO.dll
Syntax
public interface IFile
Methods
Copy(String, String)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
Declaration
void Copy(string sourceFileName, string destinationFileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceFileName | The file to copy. |
System.String | destinationFileName | The name of the destination file. This cannot be a directory or an existing file. |
Exceptions
Type | Condition |
---|---|
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentNullException |
|
System.ArgumentException |
|
System.IO.DirectoryNotFoundException | The path specified in |
System.IO.FileNotFoundException | File specified in |
System.IO.IOException |
-or- An I/O error has occurred. |
System.NotSupportedException |
|
Copy(String, String, Boolean)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
Declaration
void Copy(string sourceFileName, string destFileName, bool overwrite)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceFileName | The file to copy. |
System.String | destFileName | The name of the destination file. This cannot be a directory. |
System.Boolean | overwrite | true if the destination file can be overwritten; otherwise, false. |
Exceptions
Type | Condition |
---|---|
System.UnauthorizedAccessException | The caller does not have the required permission. -or- destFileName is read-only. |
System.ArgumentException |
-or- sourceFileName or destFileName specifies a directory.
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The path specified in |
System.IO.FileNotFoundException |
|
System.IO.IOException |
-or- An I/O error has occurred. |
System.NotSupportedException |
|
Create(String)
Creates or overwrites a file that can be used for asynchronous reading and writing in the specified path.
Declaration
Stream Create(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path and name of the file to create. |
Returns
Type | Description |
---|---|
System.IO.Stream | A System.IO.Stream that provides read/write access to the specified path. |
Exceptions
Type | Condition |
---|---|
System.UnauthorizedAccessException | The caller does not have the required permission. -or- path specified a file that is read-only.
|
System.ArgumentException |
|
System.ArgumentNullException |
|
Delete(String)
Deletes specified file.
Declaration
void Delete(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Name of file to be deleted. Wildcard characters are not supported. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException | Specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | Specified file is in use. |
System.NotSupportedException |
|
System.UnauthorizedAccessException | Caller does not have required permission. -or-
-or- File is an executable file that is in use. -or-
|
Exists(String)
Determines whether specified file exists.
Declaration
bool Exists(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | File to check. |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetAttributes(String)
Gets the System.IO.FileAttributes of the file on the path.
Declaration
FileAttributes GetAttributes(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the file. |
Returns
Type | Description |
---|---|
System.IO.FileAttributes | The System.IO.FileAttributes of the file on the path. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.NotSupportedException |
|
System.IO.FileNotFoundException |
|
System.IO.DirectoryNotFoundException |
|
System.IO.IOException | This file is being used by another process. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
Move(String, String)
Moves a specified file to a new location, providing the option to specify a new file name.
Declaration
void Move(string sourceFileName, string destFileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceFileName | The name of the file to move. Can include a relative or absolute path. |
System.String | destFileName | The new path and name for the file. |
Exceptions
Type | Condition |
---|---|
System.IO.IOException | The destination file already exists. -or- sourceFileName was not found.
|
System.ArgumentNullException |
|
System.ArgumentException |
|
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The path specified in |
System.NotSupportedException |
|
Open(String, FileMode)
Opens a System.IO.FileStream on the specified path with read/write access.
Declaration
Stream Open(string path, FileMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to open. |
System.IO.FileMode | mode | A System.IO.FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten. |
Returns
Type | Description |
---|---|
System.IO.Stream | A System.IO.Stream opened in the specified mode and path, with read/write access and not shared. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The specified path is invalid, (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
|
System.ArgumentOutOfRangeException |
|
System.IO.FileNotFoundException | The file specified in
|
System.NotSupportedException |
|
OpenRead(String)
Opens an existing file for reading.
Declaration
Stream OpenRead(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to be opened for reading. |
Returns
Type | Description |
---|---|
System.IO.Stream | A read-only System.IO.Stream on the specified path. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException | The specified |
System.UnauthorizedAccessException |
|
System.IO.FileNotFoundException | The file specified in |
System.NotSupportedException |
|
System.IO.IOException | An I/O error occurred while opening the file. |
ReadAllBytes(String)
Opens a binary file, reads contents of file into a byte array, and then closes file.
Declaration
byte[] ReadAllBytes(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | File to open for reading. |
Returns
Type | Description |
---|---|
System.Byte[] | A byte array containing data of file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException | Specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening file. |
System.IO.FileNotFoundException | File specified in |
System.NotSupportedException |
|
System.Security.SecurityException | Caller does not have required permission. |
System.UnauthorizedAccessException | This operation is not supported on current platform. -or-
-or- Caller does not have required permission. |
ReadAllLines(String)
Opens a text file, reads all lines of the file, and then closes the file.
Declaration
IEnumerable<string> ReadAllLines(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to read from. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> | A string enumeration containing all lines of the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException | Either |
System.IO.DirectoryNotFoundException |
|
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
-or- This operation is not supported on the current platform.-or- path is a directory.
-or- The caller does not have the required permission. |
System.IO.FileNotFoundException | File specified in |
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
ReadAllText(String)
Opens a text file, reads all lines of the file, and then closes the file.
Declaration
string ReadAllText(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to open for reading. |
Returns
Type | Description |
---|---|
System.String | A string containing all lines of the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
|
System.IO.FileNotFoundException | The file specified in |
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
ReadAllText(String, Encoding)
Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
Declaration
string ReadAllText(string path, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to open for reading. |
System.Text.Encoding | encoding | The encoding applied to the contents of the file. |
Returns
Type | Description |
---|---|
System.String | A string containing all lines of the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
|
System.IO.FileNotFoundException | The file specified in |
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
SetAttributes(String, FileAttributes)
Sets the specified System.IO.FileAttributes of the file on the specified path.
Declaration
void SetAttributes(string path, FileAttributes fileAttributes)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the file. |
System.IO.FileAttributes | fileAttributes | A bitwise combination of the enumeration values. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.NotSupportedException |
|
System.IO.DirectoryNotFoundException | The specified path is invalid, (for example, it is on an unmapped drive). |
System.IO.FileNotFoundException | The file cannot be found. |
System.UnauthorizedAccessException |
|
SetCreationTime(String, DateTime)
Sets the date and time the file was created.
Declaration
void SetCreationTime(string path, DateTime creationTime)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file for which to set the creation date and time information. |
System.DateTime | creationTime | A System.DateTime containing the value to set for the creation date and time of path. This value is expressed in local time. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.IOException | An I/O error occurred while performing the operation. |
System.ArgumentOutOfRangeException |
|
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.NotSupportedException |
|
SetLastWriteTimeUtc(String, DateTime)
Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.
Declaration
void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file for which to set the date and time information. |
System.DateTime | lastWriteTimeUtc | A DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time. |
WriteAllBytes(String, Byte[])
Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
void WriteAllBytes(string path, byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to write to. |
System.Byte[] | bytes | The bytes to write to the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified |
System.IO.DirectoryNotFoundException | The specified |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
-or- This operation is not supported on the current platform.-or- path specified a directory.
-or- The caller does not have the required permission. |
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
WriteAllLines(String, IEnumerable<String>)
Creates a new file, writes a collection of strings contents
to the file,
and then closes the file.
Declaration
void WriteAllLines(string path, IEnumerable<string> contents)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to write to. |
System.Collections.Generic.IEnumerable<System.String> | contents | The lines to write to the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException | Either |
System.IO.DirectoryNotFoundException |
|
System.IO.IOException | An I/O error occurred while opening the file. |
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
System.UnauthorizedAccessException |
-or- This operation is not supported on the current platform.-or- path is a directory.
-or- The caller does not have the required permission. |
WriteAllText(String, String)
Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
void WriteAllText(string path, string contents)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to write to. |
System.String | contents | The string to write to the file. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
|
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |
WriteAllText(String, String, Encoding)
Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
void WriteAllText(string path, string contents, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to write to. |
System.String | contents | The string to write to the file. |
System.Text.Encoding | encoding | The encoding to apply to the string. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.PathTooLongException | The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. |
System.IO.DirectoryNotFoundException | The specified path is invalid (for example, it is on an unmapped drive). |
System.IO.IOException | An I/O error occurred while opening the file. |
System.UnauthorizedAccessException |
|
System.NotSupportedException |
|
System.Security.SecurityException | The caller does not have the required permission. |