open a text file that in use by another process
i have this code but it wont open the log file of a program thats running and using that log file how can i watch that log file and store it in a string when it changes?
Code:
int count;
String^ sFileName;
String^ sLine;
private: System::Void b1_Click(System::Object^ sender, System::EventArgs^ e) {
count = 0;
ofd1->ShowDialog();
sFileName = ofd1->FileName;
filenamelbl->Text=sFileName; // set the path to the file we are going to open
StreamReader^ din = File::OpenText(sFileName);
while ((sLine = din->ReadLine()) != nullptr) {
count++;
sLine = ("line {0}: {1}", count, sLine );
logtb->Text =logtb->Text + sLine + "\r\n";
}
}
};
}