May 01
To get the path of the current user's temporary folder, call the GetTempPath method in the System.IO namespace:
string tempPath = System.IO.Path.GetTempPath();
On Windows Vista and 7, this method will return the following path:
C:\Users\UserName\AppData\Local\Temp\
Popularity: 2% [?]
Apr 21
It’s easy to read a file into a byte array. Just use the File.ReadAllBytes static method. This opens a binary file in read-only mode, reads the contents of the file into a byte array, and then closes the file.
string filePath = @"C:\test.doc";
byte[] byteArray = File.ReadAllBytes( filePath );
Popularity: 4% [?]
Apr 12
The .NET FolderBrowserDialog class does not have an InitialDirectory property like the OpenFileDialog class. But fortunately, it’s quite easy to set an initial folder in the FolderBrowserDialog:
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.RootFolder = Environment.SpecialFolder.Desktop;
dialog.SelectedPath = @"C:\Program Files";
if (dialog.ShowDialog() == DialogResult.OK)
{
Console.WriteLine( dialog.SelectedPath );
}
Note that you can choose other RootFolder’s like MyComputer and MyDocuments. The SelectedPath must be a child of the RootFolder for this to work.
Given the sample code above, the dialog may look like this:

Popularity: 3% [?]
Feb 20
It’s easy to read a string one line at a time. Here is a console program that demonstrates how:
Read the rest of this entry »
Popularity: 24% [?]
Feb 19
It’s fairly easy to convert a C# String to a Stream and vice-versa.
Read the rest of this entry »
Popularity: 93% [?]
Jan 15
Here is the code to read a text file from disk one line at a time into a string. This code ensures the file exists and properly closes the file if an exception occurs.
Read the rest of this entry »
Popularity: 46% [?]
Jul 17
It's not a trivial exercise to validate a file path on a Windows PC. There are a few special cases depending on the file system and operating subsystem:
Read the rest of this entry »
Popularity: 42% [?]
Jul 16
It's easy to display an RTF file — that was embedded as a resource in a C# program — in a Windows Form RichTextControl.
Read the rest of this entry »
Popularity: 17% [?]
Jul 09
Sadly there is no built-in function in System.IO that will copy a folder and its contents. Following is a simple recursive algorithm that copies a folder, its sub-folders and files, creating the destination folder if needed. For simplicity, there is no error handling; an exception will throw if anything goes wrong, such as null or invalid paths or if the destination files already exist.
Read the rest of this entry »
Popularity: 33% [?]
Jul 01
Here is the easiest way to read an entire text file into a C# string:
string s = System.IO.File.ReadAllText( path );
Popularity: 51% [?]