Method CopyFileToTemp
CopyFileToTemp(FileInfo)
Creates a temporary copy of the specified file and returns a FileStream for it. The temporary file will be deleted upon closing the returned FileStream.
Declaration
public static FileInfo CopyFileToTemp(FileInfo sourceFile)
Parameters
Type | Name | Description |
---|---|---|
FileInfo | sourceFile | Source file to be copied. |
Returns
Type | Description |
---|---|
FileInfo | A FileStream that provides access to the temporary copy of the file. The file is opened in read-write mode with read-write sharing and is set to be deleted upon closing the stream. |
Remarks
The method ensures the temporary file has a unique name by appending the original file name to a system-generated temporary file name.
Exceptions
Type | Condition |
---|---|
IOException | Thrown when the file copy operation fails. |