Class IOUtil
Summary description for IOUtil.
Inheritance
Inherited Members
Namespace: ImageVault.Common.Lib.IO
Assembly: ImageVault.Common.dll
Syntax
public static class IOUtil
Remarks
2011-04-04 dan: Created
Methods
CopyStream(Stream, Stream)
Copies data from one stream to another
Declaration
public static void CopyStream(Stream inStream, Stream outStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inStream | The System.IO.Stream to read from |
System.IO.Stream | outStream | The System.IO.Stream to write to |
CopyStream(Stream, Stream, IOUtil.CopyStreamStats)
Copies data from one stream to another
Declaration
public static void CopyStream(Stream inStream, Stream outStream, IOUtil.CopyStreamStats stats)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inStream | The System.IO.Stream to read from |
System.IO.Stream | outStream | The System.IO.Stream to write to |
IOUtil.CopyStreamStats | stats | Optional IOUtil.CopyStreamStats instance to populate with operation details |
EmptyDirectory(DirectoryInfo, Boolean)
Empties the supplied directory of files and subdirectories (if recursive)
Declaration
public static void EmptyDirectory(DirectoryInfo dir, bool recursive)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir | The System.IO.DirectoryInfo to empty |
System.Boolean | recursive | If subdirs should be removed as well as the files.. |
EmptyDirectory(DirectoryInfo, Boolean, Boolean)
Empties the supplied directory of files and subdirectories (if recursive)
Declaration
public static void EmptyDirectory(DirectoryInfo dir, bool recursive, bool ignoreAttributes)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir | The System.IO.DirectoryInfo to empty |
System.Boolean | recursive | If subdirs should be removed as well as the files.. |
System.Boolean | ignoreAttributes | If all items attribute should be set to System.IO.FileAttributes.Normal before deleting. |
EmptyDirectory(String, Boolean)
Empties the supplied directory of files and subdirectories (if recursive)
Declaration
public static void EmptyDirectory(string dir, bool recursive)
Parameters
Type | Name | Description |
---|---|---|
System.String | dir | The directory to empty |
System.Boolean | recursive | If subdirs should be removed as well as the files.. |
EmptyDirectory(String, Boolean, Boolean)
Empties the supplied directory of files and subdirectories (if recursive)
Declaration
public static void EmptyDirectory(string dir, bool recursive, bool ignoreAttributes)
Parameters
Type | Name | Description |
---|---|---|
System.String | dir | The directory to empty |
System.Boolean | recursive | If subdirs should be removed as well as the files.. |
System.Boolean | ignoreAttributes | If all items attribute should be set to System.IO.FileAttributes.Normal before deleting. |
FindDirectoryByName(DirectoryInfo, String, Boolean)
Returns a DirectoryInfo to a file in the supplied directory that doesn't exists. The filename is randomized and is
nrOfCharacters
long with the same extension that the supplied one.
Declaration
public static DirectoryInfo FindDirectoryByName(DirectoryInfo dir, string directoryName, bool recursive)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir | The root folder to start searching in |
System.String | directoryName | The directoryName to search for |
System.Boolean | recursive | If subdirs should be searched |
Returns
Type | Description |
---|---|
System.IO.DirectoryInfo | A DirectoryInfo if there is at match, null otherwise |
GetFolderPath(String, Boolean)
Gets the path to the supplied folder
Declaration
public static string GetFolderPath(string rawPath, bool ensureExists = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | rawPath | Raw path (including env variables) |
System.Boolean | ensureExists | If true (default), creates the folder if it does not exist |
Returns
Type | Description |
---|---|
System.String | Path to the folder |
GetNewUniqueDirectoryInfo(DirectoryInfo, Int32)
Creates a new DirectoryInfo in the supplied parent folder
Declaration
public static DirectoryInfo GetNewUniqueDirectoryInfo(DirectoryInfo parent, int nrOfCharacters)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | parent | |
System.Int32 | nrOfCharacters |
Returns
Type | Description |
---|---|
System.IO.DirectoryInfo |
GetNewUniqueFileInfo(DirectoryInfo, Int32, String)
Returns a FileInfo to a file in the supplied directory that doesn't exists. The filename is randomized and is
nrOfCharacters
long with the same extension that the supplied one.
Declaration
public static FileInfo GetNewUniqueFileInfo(DirectoryInfo dir, int nrOfCharacters, string extension)
Parameters
Type | Name | Description |
---|---|---|
System.IO.DirectoryInfo | dir | The target folder |
System.Int32 | nrOfCharacters | length of the filename (excluding extension) |
System.String | extension | extension of the file, or null if extension should be omitted |
Returns
Type | Description |
---|---|
System.IO.FileInfo | A unique FileInfo |
GetNewUniqueFileInfo(String, Int32, String)
Returns a FileInfo to a file in the supplied directory that doesn't exists. The filename is randomized and is
nrOfCharacters
long with the same extension that the supplied one.
Declaration
public static FileInfo GetNewUniqueFileInfo(string path, int nrOfCharacters, string extension)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path of the target folder |
System.Int32 | nrOfCharacters | length of the filename (excluding extension) |
System.String | extension | extension of the file |
Returns
Type | Description |
---|---|
System.IO.FileInfo | A unique FileInfo |
GetRandomFileCharacter()
Returns a random coosen filename character
Declaration
public static char GetRandomFileCharacter()
Returns
Type | Description |
---|---|
System.Char |
GetTextFileEncoding(String)
Calculates the encoding of the text file based on the byte order mark (bom) found in the beginning of the file.
Declaration
public static Encoding GetTextFileEncoding(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The path to the file to examine. |
Returns
Type | Description |
---|---|
System.Text.Encoding | The found encoding |
RandomizeFileName(Int32)
Returns a randomized filename of the number of characters that is supplied.
Declaration
public static string RandomizeFileName(int nrOfCharacters)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | nrOfCharacters |
Returns
Type | Description |
---|---|
System.String |
ReadStream(Stream)
Reads a stream and returns the data
Declaration
public static byte[] ReadStream(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream |
Returns
Type | Description |
---|---|
System.Byte[] |
RemoveIllegalFileNameCharacters(String)
Parses the given string and removes all characters that is not allowed in filenames. Even the dot (.) is stripped.
Declaration
public static string RemoveIllegalFileNameCharacters(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name to parse |
Returns
Type | Description |
---|---|
System.String | The parsed string |