-
File.ReadAllText(filePath);
-> Reads / Returns the data of a file as STRING -
File.ReadAllLines(filePath);
-> Reads /Returns the contents of a file and stores each line at a new index in a STRING[] -
File.ReadAllBytes(filePath);
-> Reads / Returns the contents of a file as binary data and stores the data in a BYTE[] -
File.WriteAllText(filePath, data);
-> Overwrites the content with the content of a string variable -
File.WriteAllLines(filePath, data);
-> Write content of a string array - each entry = new line -
File.AppendAllText(filePath, data);
-> Appends STRING -
File.AppendAllLines(filePath, data);
-> Append content of a string array
File.Copy(sourceFilePath, destinationFilePath, overWrite);
-> Copying existing file to a new location
NOTE: The "overwrite parameter" passed to the "Copy method" call indicates
that the copy process should overwrite an existing file if it exists
at the destination path.
If you pass false to the "Copy method" call, and the file already exists
then the "Common Language Runtime" (CLR) will throw a "System.IO.IOException".
File.Delete(sourceFilePath);
-> Deletes existing fileFile.Exists(sourceFilePath);
-> Returns BOOLEANFile.GetCreationTime(sourceFilePath);
-> Returns creation time as DATETIME
FileInfo flInfo = new FileInfo(sourceFilePath);
<- !This is the file connection!flInfo.CopyTo(destinationFilePath, overwrite);
NOTE: The "overwrite parameter" in the "CopyTo method" indicates that the copy process should overwrite an existing file if it exists at the specified destination file path. If you pass false to the "CopyTo method", and the file already exists then the "Common Language Runtime" (CLR) will throw a "System.IO.IOException".
flInfo.Delete();
-> Deletes content of the existing fileflInfo.DirectoryName;
-> Returns the directory path as STRINGflInfo.Exists;
-> Return BOOLEANflInfo.Extension;
-> Returns the file extension as STRINGflInfo.Length;
-> Returns the length in bytes (LONG)
Directory.CreateDirectory(sourceDirPath);
-> Creates a new directoryDirectory.Delete(sourceDirPath, deleteRecursivly);
-> Deletes a direcotry at a specific path
NOTE: The "deleteRecursively parameter" passed into the "Delete method" specifies whether the delete process should delete any content that may exist in the directory. If you pass false into the "Delete method", and the directory is not empty then the "Common Language Runtime" CLR will throw a "System.IO.IOException".
Directory.Exists(sourceDirPath);
-> Returns a BOOLEANDirectory.GetDirectories(sourceDirPath);
-> Returns a STRING[] of subdirectories within a specific directoryDirectory.GetFiles(sourceDirPath);
-> Returns a STRING[] of files within a specific directory
DirectoryInfo directory = new DirectoryInfo(sourceDirPath);
<- !This is the directory connection!
directory.Create();
-> Creates new directorydirectory.Delete(deleteRecursively);
-> Deletes directory
NOTE: The "recursivelyDeleteSubContent parameter" passed to the "Delete method" call indicates whether the delete process should delete any content that may exist in the directory. If you pass false to the "Delete method" call, and the directory is not empty then the "Common Language Runtime" CLR will throw a "System.IO.IOException".
directory.Exists;
-> Returns a BOOLEANdirectory.FullName;
-> Returns the full path as STRING
DirectoryInfo[] subDirectories = directory.GetDirectories();
The "GetDirectories" method gets a list of all subdirectories within a specific directory on the file system. In contrast to the static File.GetDirectories method, this instance method returns an array of type DirectoryInfo, that enables you to use each of the instance properties for each subdirectory.
FileInfo[] subFiles = directory.GetFiles();
The "GetFiles" method gets a list of all the files within a specific directory on the file system. In contrast to the static File.GetFiles method, this instance method returns an array of type
FileInfo, that enables you to use each of the instance properties for each file.