There are 2 classes, depending on whether you are doing a single file operation, or whether you need repeated cached file access over a length of time: (more…)
Filename Not Permitted Characters
//Remove any characters not allowed in filenames characters:- \ / | : * " ? < >
MyString = MyString->Replace("\\", "-");
MyString = MyString->Replace("/", "-");
MyString = MyString->Replace("|", "-");
MyString = MyString->Replace(":", "-");
MyString = MyString->Replace("*", "-");
MyString = MyString->Replace("\"", " ");
MyString = MyString->Replace("?", " ");
MyString = MyString->Replace("<", " ");
MyString = MyString->Replace(">", " ");
Obtaining Hard Disk Information
using namespace System::IO;
try
{
array<DriveInfo^> ^allDrives = DriveInfo::GetDrives();
(more...)
Open File Dialog
using namespace System::IO;
Open File Dialog Example
String ^LastFileDirectory;
String ^Filename;
(more...)
Reading File Version
try
{
FileVersionInfo ^FileVersion1 = FileVersionInfo::GetVersionInfo(Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles) + "\\Some Folder\\SomeApplication.exe");
sTemp = "App Version: " + Convert::ToString(FileVersion1->FileVersion) + "\r\n";
}
catch (Exception ^)
{
}
Storing Class Data, Arrays Etc
See Serialization
User select directory example
String ^SelectedDirectory;
FolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog();
//Setup dialog box
SelectFolderDialog->Description = "Select directory to store files to";
SelectFolderDialog->ShowNewFolderButton = true;
SelectFolderDialog->RootFolder = System::Environment::SpecialFolder::Desktop;
try
{
SelectFolderDialog->SelectedPath = SelectedDirectory; //Try and use last selection
}
catch (Exception ^)
{
}
(more...)
Working With Directories
using namespace System::IO;
Does directory exist?
(Note paths can include a filename if you wish) (more…)
Write File Thread Safe
This example is based on writing a file from asynchronously received TCP packets. FileStream->Write is not thread safe, so this approach deals with letting file write occur in the background and waiting for it to complete before writing the next received block of data bytes. (more…)



