It doesn't matter if the filename is not static, you stated your logic
is to be dependent on the extension, which is what the code I have supplied
does. It only works on the extension. There is no first, second, or third
order of processing. It chooses one course of action based on the
extension.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Nicholas, the default file would have an extension of .DAT, and would be
> the
[quoted text clipped - 55 lines]
>> >
>> > Brian
Brian Cook - 20 Aug 2007 21:16 GMT
Nicholas, this is what I have and it does work. How would I make one of them
"default"?
Thanks,
private void OpenFile()
{
try
{
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
if (OpenFileDialog.FileName == "")
{
return;
}
string strExt;
strExt =
System.IO.Path.GetExtension(OpenFileDialog.FileName);
strExt = strExt.ToLower();
//if (strExt == ".rtf")
switch (strExt)
{
case ".rtf":
System.IO.StreamReader txtReader;
txtReader = new
System.IO.StreamReader(OpenFileDialog.FileName);
rtbDoc.Text = txtReader.ReadToEnd();
txtReader.Close();
txtReader = null;
rtbDoc.SelectionStart = 0;
rtbDoc.SelectionLength = 0;
break;
case ".dat":
rtbDoc.Text =
Streamer.LayoutInput(OpenFileDialog.FileName);
break;
case ".txt":
System.IO.StreamReader txtReader;
txtReader = new
System.IO.StreamReader(OpenFileDialog.FileName);
rtbDoc.Text = txtReader.ReadToEnd();
txtReader.Close();
txtReader = null;
rtbDoc.SelectionStart = 0;
rtbDoc.SelectionLength = 0;
break;
}
currentFile = OpenFileDialog.FileName;
rtbDoc.Modified = false;
this.Text = "Train Control Editor: " +
currentFile.ToString();
}
else
{
MessageBox.Show("Open File request cancelled by user.",
"Cancelled");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}
> It doesn't matter if the filename is not static, you stated your logic
> is to be dependent on the extension, which is what the code I have supplied
[quoted text clipped - 61 lines]
> >> >
> >> > Brian
Nicholas Paldino [.NET/C# MVP] - 20 Aug 2007 21:35 GMT
Brian,
You can use the default case, like so:
switch (<expression>)
{
case <case expression>:
// Do something.
break;
default:
// Do things here in the event none of the case expressions match.
break;
}

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Nicholas, this is what I have and it does work. How would I make one of
> them
[quoted text clipped - 132 lines]
>> >> >
>> >> > Brian
Brian Cook - 20 Aug 2007 21:38 GMT
Boy was that simple!
I guess I am over-complicating things when I don't know them.
Thanks Nicholas.
> Brian,
>
[quoted text clipped - 147 lines]
> >> >> >
> >> >> > Brian