title: Creating an openFileDialog method in C#
body: <p>My .NET Windows application has multiple instances of being able to open and view text files.  I have no problem getting this to work when I create individual openFileDialogs through my code.  In trying to clean up my code, I created a method, but I am fairly new and am getting a red squiggly.  Can someone please look at this and tell me what I am doing wrong?  Thanks.</p>
  
  <p>I am trying to call the method as shown here:</p>
  
  <pre><code>textBox_ViewFile.Text = LoadFromFile();
  </code></pre>
  
  <p>Then my method is as follows:</p>
  
  <pre><code>static string[] LoadFromFile()
      {
          OpenFileDialog openFileDialog1 = new OpenFileDialog();
          openFileDialog1.InitialDirectory = "c:\\";
          openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
          openFileDialog1.RestoreDirectory = false;
          openFileDialog1.ShowHelp = true;
  
          if (openFileDialog1.ShowDialog() == DialogResult.OK)
          {
              try
              {
                  if (openFileDialog1.OpenFile() != null)
                  {
                      return (File.ReadAllLines(openFileDialog1.FileName));
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
              }
          }
      }
  </code></pre>
  
  <p>In this case, I am getting a syntax error in VS2010 under "LoadFromFile()" from </p>
  
  <pre><code>static string[] LoadFromFile()"
  </code></pre>