Folks:
I am trying to create a simple C# windows app that contains a couple of file list boxes and a text box. When the entry in the file list box is selected, I want the contents to display in the text box. Simple enough. My problem is that I am trying to display Microsoft SMS MIF files from SMS clients that had an issue trying to insert their MIF file into the SMS database. When I look at the file using notepad, the file contains wierd characters like these: Õ throughout the file. Note: these characters are supposed to be there by design as SMS creates the files that way.
When I try to dump the file into a text box, all I get is the first wierd character. I am guessing the text reader is interpreting the character as an end of file. Does anyone know how I can just dump the whole file into the text box, regardles off what text it contains? My code is listed below:
Thanks,
Michael
I am trying to create a simple C# windows app that contains a couple of file list boxes and a text box. When the entry in the file list box is selected, I want the contents to display in the text box. Simple enough. My problem is that I am trying to display Microsoft SMS MIF files from SMS clients that had an issue trying to insert their MIF file into the SMS database. When I look at the file using notepad, the file contains wierd characters like these: Õ throughout the file. Note: these characters are supposed to be there by design as SMS creates the files that way.
When I try to dump the file into a text box, all I get is the first wierd character. I am guessing the text reader is interpreting the character as an end of file. Does anyone know how I can just dump the whole file into the text box, regardles off what text it contains? My code is listed below:
Code:
try
{
// Determine if the file exists before loading.
if (System.IO.File.Exists(file))
{
// Open the file and use a TextReader to read the contents into the TextBox.
System.IO.FileInfo myFile = new System.IO.FileInfo(file);
System.IO.TextReader myData = myFile.OpenText();;
txtInventoryFile.Text = myData.ReadToEnd().ToString();
myData.Close();
}
}
// Exception is thrown by the OpenText method of the FileInfo class.
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("The file you specified does not exist.");
}
// Exception is thrown by the ReadToEnd method of the TextReader class.
catch(System.IO.IOException)
{
MessageBox.Show("There was a problem loading the file into the TextBox. Ensure that the file is a valid text file.");
}
Michael