Skip to content

File I/O Library

Path


Description

Exposes functionality with regards to Strings containing file/directory path information

Methods

Combine(string, string)

Description

Combines two strings into a path.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Part1 string The first part of the path to combine.
Part2 string The second part of the path to combine.

Syntax

var combinedPath = FileIOLib.Path.Combine("Program Files (x86)","IIS");



Combine(string, string, string)

Description

Combines three strings into a path.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Part1 string The first part of the path to combine.
Part2 string The second part of the path to combine.
Part3 string The third part of the path to combine.

Syntax

var combinedPath = FileIOLib.Path.Combine("Program Files (x86)","IIS", "External Disk Cache");



Combine(string, string, string, string)

Description

Combines four strings into a path.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Part1 string The first part of the path to combine.
Part2 string The second part of the path to combine.
Part3 string The third part of the path to combine.
Part4 string The fourth part of the path to combine.

Syntax

var combinedPath = FileIOLib.Path.Combine("Program Files (x86)","IIS", "External Disk Cache", "ecache.dll");



GetTempPath()

Description

Returns the path of the current user’s temporary folder.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Syntax

string result = FileIOLib.Path.GetTempPath();



GetFileName(string)

Description

Returns the file name and extension of the specified path string. The returned value is null if the file path is null.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Path string The path string from which to obtain the file name and extension.

Syntax

string fileName = CommonLib.Utilities.GetUploadsPath("file.txt");
string result = FileIOLib.Path.GetFileName(fileName);



GetFileNameWithoutExtension(string)

Description

Returns the file name of the specified path string without the extension. This method does not verify that the path or file name exists.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Path string The path of the file.

Syntax

string fileName = CommonLib.Utilities.GetUploadsPath("file.txt");
string result = FileIOLib.Path.GetFileNameWithoutExtension(fileName);



GetFullPath(string)

Description

Returns the absolute path for the specified path string.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Path string The file or directory for which to obtain absolute path information.

Syntax

string fileName = CommonLib.Utilities.GetUploadsPath("file.txt");
string result = FileIOLib.Path.GetFullPath(fileName);



GetDirectoryName(string)

Description

Returns the directory information for the specified path string.

Return Type : string

Static : Yes

Namespace : FileIOLib.Path

Parameters

Name Data Type Description
Path string The path of a file or directory.

Syntax

string filePath = CommonLib.Utilities.GetUploadsPath("test/file.txt");
string directoryName = FileIOLib.Path.GetDirectoryName(filePath);



Directory


Description

Exposes functionality that creates, deletes, checks and enumerates directories, subdirectories and files

Methods

Create(string)

Description

Creates all directories and subdirectories in the specified path unless they already exist.

Return Type : void

Static : Yes

Namespace : FileIOLib.Directory

Parameters

Name Data Type Description
Path string The directory to create.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("path-to-directory");
FileIOLib.Directory.Create(path);



Exists(string)

Description

Determines whether the given path refers to an existing directory. Returns true if path refers to an existing directory or false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

Return Type : bool

Static : Yes

Namespace : FileIOLib.Directory

Parameters

Name Data Type Description
Path string The path to find.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("Home");
if(!FileIOLib.Directory.Exists()){
    FileIOLib.Directory.Create();
}



GetFiles(string)

Description

Returns the names of files (including their paths) in the specified directory. Returns an array of the full names (including paths) for the files in the specified directory, or an empty array if no files are found.

Return Type : Array

Static : Yes

Namespace : FileIOLib.Directory

Parameters

Name Data Type Description
Path string The relative or absolute path to the directory to search. This string is not case-sensitive.

Syntax

string path =  CommonLib.Utilities.GetUploadsPath("Home");
Array[string] files = FileIOLib.Directory.GetFiles(path);



GetDirectories(string)

Description

Returns the names of subdirectories (including their paths) in the specified directory. Returns an array of the full names (including paths) of subdirectories in the specified path, or an empty array if no directories are found.

Return Type : Array

Static : Yes

Namespace : FileIOLib.Directory

Parameters

Name Data Type Description
Path string The relative or absolute path to the directory to search. This string is not case-sensitive.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("Images");
Array[string] files = FileIOLib.Directory.GetDirectories(path);



Delete(string)

Description

Deletes an empty directory from a specified path.

Return Type : void

Static : Yes

Namespace : FileIOLib.Directory

Parameters

Name Data Type Description
Path string The name of the empty directory to remove. This directory must be writable and empty.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("Images");
FileIOLib.Directory.Delete(path);



File


Description

Exposes functionality that creates, copies, moves and deletes a single file. Provides numerous methods that read and write from and to the loaded file

Methods

Exists(string)

Description

Determines whether the specified file exists. Returns true if the caller has the required permissions and path contains the name of an existing file. Otherwise returns false.

Return Type : bool

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to check.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if(!FileIOLib.File.Exists(path)){
    FileIOLib.File.CreateNew(path);
}



CreateNew(string)

Description

Creates or overwrites a file in the specified path.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The path and name of the file to create.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if(!FileIOLib.File.Exists(path)){
    FileIOLib.File.CreateNew(path);
}



WriteAllTo(string, string)

Description

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.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to write to.
Text string The string to write to the file.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
// Create a file to write to.
string createText = "Hello and Welcome";
FileIOLib.File.WriteAllTo(path, createText);
}



WriteAllTo(string, string, int)

Description

Creates a new file, writes the specified string to the file with code page encoding, and then closes the file. If the target file already exists, it is overwritten.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to write to.
Text string The string to write to the file.
CodePage int The encoding to use

Syntax

int codePage = 1252; // windows 1252 encoding
string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    string createText = "Hello and Welcome";
    FileIOLib.File.WriteAllTo(path, createText, codePage);
}



WriteAllTo(string, Collection[byte])

Description

Creates a new file, writes the collection of bytes to the file, and then closes the file. If the target file already exists, it is overwritten.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to write to.
Data Collection The string, represented as a collection of bytes, to write to the file.

Syntax

//load collection[bytes]
Collection[byte] image = myobject.Image;
string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    FileIOLib.File.WriteAllTo(path, image);
}



WriteAllTo(string, string, bool)

Description

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.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to write to.
Text string The string to write to the file.
WithBOM bool Boolean to specify if file will be written with BOM format or not

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
string txt = "Hello!";
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    FileIOLib.File.WriteAllTo(path, txt, true);
}



AppendAllTo(string, string)

Description

Appends the specified string to an existing file, and then closes the file. If file does not exist, it is created.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to append to.
Text string The string to append to the file.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");                               
FileIOLib.File.AppendAllTo(path, "Hello!");                                



AppendAllTo(string, string, int)

Description

Appends the specified string to an existing file with code page encoding, and then closes the file. If file does not exist, it is created.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to append to.
Text string The string to append to the file.
CodePage int The encoding to use

Syntax

int codePage = 1252; // windows 1252 encoding
string path = CommonLib.Utilities.GetUploadsPath("test.txt");                                
string txt = "Hello and Welcome Again";
FileIOLib.File.AppendAllTo(path, txt, codePage);                                



AppendAllTo(string, Collection[byte])

Description

Appends the collection of bytes to an existing file, and then closes the file. If file does not exist, it is created.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to append to.
Data Collection The string, represented as a collection of bytes, to append to the file.

Syntax

//load collection[bytes]
Collection[byte] image = myobject.Image;
string path = CommonLib.Utilities.GetUploadsPath("test.txt");      

// Append to File
FileIOLib.File.AppendAllTo(path, image);                                



AppendAllTo(string, string, bool)

Description

Appends the specified string to an existing file, and then closes the file. If file does not exist, it is created.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to append to.
Text string The string to append to the file.
WithBOM bool Boolean to specify if file will be written with BOM format or not

Syntax

string txt = "Hello!";
string path = CommonLib.Utilities.GetUploadsPath("test.txt");

// Append to File
FileIOLib.File.AppendAllTo(path, txt, true);                                



ReadAllFrom(string)

Description

Opens a text file, reads all lines of the file, and then closes the file. Returns a string containing all lines of the file.

Return Type : string

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to open for reading.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    string createText = "Hello and Welcome";
    FileIOLib.File.WriteAllTo(path, createText);
}
// Open the file to read from.
string readText = FileIOLib.File.ReadAllText(path);



ReadAllFrom(string, int)

Description

Opens a file, reads all lines of the file with the specified encoding, and then closes the file. Returns a string containing all lines of the file.

Return Type : string

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to open for reading.The encoding applied to the contents of the file.
CodePage int The encoding applied to the contents of the file.

Syntax

int codePage = 1252; // windows 1252 encoding
string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    string createText = "Hello and Welcome";
    FileIOLib.File.WriteAllTo(path, createText, codePage);
}
// Open the file to read from.
string readText = FileIOLib.File.ReadAllText(path,encodingCodePage);



ReadAllFromUsed(string)

Description

Reads content from an already opened text file and returns it as a string.

Return Type : string

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to open for reading.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
if (!FileIOLib.File.Exists(path))
{
    // Create a file to write to.
    string createText = "Hello and Welcome";
    FileIOLib.File.WriteAllTo(path, createText);
}
// Open the file to read from.
string readText = FileIOLib.File.ReadAllFromUsed(path);



ReadAllBytesFrom(string)

Description

Opens a binary file, reads the contents of the file into a byte array, and then closes the file. Returns a byte array containing the contents of the file.

Return Type : Array

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to open for reading.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
Array[byte] readText = FileIOLib.File.ReadAllBytesFrom(path);



ReadAllBytesFromUsed(string)

Description

Reads all bytes from an already opened a binary file. Returns a byte array containing the contents of the file.

Return Type : Array

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The file to open for reading.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
Array[byte] readText = FileIOLib.File.ReadAllBytesFromUsed(path);



Delete(string)

Description

Deletes the specified file.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
Path string The name of the file to be deleted.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
FileIOLib.File.Delete(path);



Copy(string, string, bool)

Description

Copies an existing file to a new file. Overwriting a file of the same name is allowed.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
FromPath string The file to copy.
ToPath string The name of the destination file. This cannot be a directory.
Overwite bool true if the destination file can be overwritten. Otherwise, false.

Syntax

string FromPath = CommonLib.Utilities.GetUploadsPath("test.txt");
string ToPath = CommonLib.Utilities.GetUploadsPath("test1.txt");
FileIOLib.File.Copy(FromPath, ToPath, true);



Move(string, string, bool)

Description

Moves a specified file to a new location, providing the option to specify a new file name.

Return Type : void

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
FromPath string The name of the file to move.
ToPath string The new path and name for the file.
Overwite bool true if the destination file can be overwritten. Otherwise, false.

Syntax

string FromPath = CommonLib.Utilities.GetUploadsPath("test.txt");
string ToPath = CommonLib.Utilities.GetUploadsPath("test1.txt");
FileIOLib.File.Move(FromPath, ToPath, true);



ExtractLinesFrom(string, int, int)

Description

Extract specific number of lines read from path with codepage encoding . Returns the lines extracted in a Collection[string].

Return Type : Collection

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
FromPath string The name of the file to read.
NumberOfLinesToRead int How many lines to read
Codepage int The encoding applied to the contents of the file.

Syntax

string FromPath = CommonLib.Utilities.GetUploadsPath("test.txt");
FileIOLib.File.ExtractLinesFrom(FromPath, 100, 1252);



ReadLinesFrom(string, int, int, int)

Description

Extract specific number of lines starting from a line, read from path with codepage encoding . Returns the lines extracted in a Collection[string].

Return Type : Collection

Static : Yes

Namespace : FileIOLib.File

Parameters

Name Data Type Description
FromPath string The name of the file to read.
StartAtLine int The number of line to start reading
NumberOfLinesToRead int How many lines to read
Codepage int The encoding applied to the contents of the file.

Syntax

string FromPath = CommonLib.Utilities.GetUploadsPath("test.txt");
FileIOLib.File.ReadLinesFrom(FromPath,20, 100, 1252);



FileDetails


Description

Contains information regarding a loaded File

Properties

Name Data Type Static Readonly Description
Name string No No The file name and extension of the specified path string (eg. image.jpg) .
FullPath string No No String representing the directory's full path
Extension string No No The extension of the specified path (eg. .jpg)
DirectoryName string No No String representing the directory's name.
Length long No No Size, in bytes, of the current file.
IsReadonly bool No No Determines if the current file is read only.

Methods

Load(string)

Description

Get the attributes of the specified file

Return Type : FileIOLib.FileDetails

Static : Yes

Namespace : FileIOLib.FileDetails

Parameters

Name Data Type Description
FilePath string The name of the file to load.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
FileIOLib.FileDetails det = FileIOLib.FileDetails.Load(path);
DebugLib.Logger.WriteWarnLine("loaded file with name : " + det.Name);



ZipFile


Description

Exposes functionality for creating, extracting, and reading zip files.

Methods

AddFile(string)

Description

Add a file into a compressed ZIP file

Return Type : void

Static : No

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
Path string The name of the file to add to zip.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("test.txt");
FileIOLib.ZipFile zip;
zip.AddFile(path);



AddFile(string, string)

Description

Add a file into a specific directory, inside a ZIP, and then compress it

Return Type : void

Static : No

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
Path string The name of the file to add to zip.
Directory string The directory inside the zip in which the file will be added.

Syntax

string path = CommonLib.Utilities.GetUploadsPath("file.txt");
string dir = CommonLib.Utilities.GetUploadsPath("dir");
FileIOLib.ZipFile zip;
zip.AddFile(path, dir);



Save(string)

Description

Save the compressed folder, in a specified directory

Return Type : void

Static : No

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
Path string The final path of the ZIP

Syntax

string path = CommonLib.Utilities.GetUploadsPath("text.txt");
string dir = CommonLib.Utilities.GetUploadsPath("dir");
string savePath = CommonLib.Utilities.GetUploadsPath("SavedZips");
FileIOLib.ZipFile zip;
zip.AddFile(path, dir);
zip.save(savePath);



ExtractAll(string, string)

Description

Extract all files from zip path to the extraction path.

Return Type : void

Static : Yes

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
ZipFilePath string Path of zip file
ExtractPath string Path to extract zip file

Syntax

string zippath = CommonLib.Utilities.GetUploadsPath("Images.zip");
string ExtractPath = CommonLib.Utilities.GetUploadsPath("Icons");
FileIOLib.ZipFile.ExtractAll();



ExtractAllAndOverwrite(string, string)

Description

Extract all files from zip path to the extraction path. Ovewrites file if exists.

Return Type : void

Static : Yes

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
ZipFilePath string Path of zip file
ExtractPath string Path to extract zip file

Syntax

string zippath = CommonLib.Utilities.GetUploadsPath("test.zip");
string ExtractPath = CommonLib.Utilities.GetUploadsPath("test");
FileIOLib.ZipFile.ExtractAllAndOverwrite();



Read(string)

Description

Read zip file from path

Return Type : FileIOLib.ZipFile

Static : Yes

Namespace : FileIOLib.ZipFile

Parameters

Name Data Type Description
FilePath string Path of zip file

Syntax

string zippath = CommonLib.Utilities.GetUploadsPath("test.zip");
FileIOLib.ZipFile zipFileObject = FileIOLib.ZipFile.Read(zippath);



Back to top