Filtering text files in C#
<p>How do I just open files with the .txt extension, I want to my program to pop up an error message if the file is not a .txt file I want a code that can modify this code below</p>

<pre><code>private void button1_Click(object sender, EventArgs e)
{
   OpenFileDialog of = new OpenFileDialog();
   of.ShowDialog();
   textBox1.Text = of.FileName;
}
</code></pre>

<p>Can someone help let's say I want to put this loop</p>

<pre><code>if fileextension is .txt then 
OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();
            textBox1.Text = of.FileName;
else show error message(like can not open this file)
</code></pre>
