title: Streamwriter - Array of strings to .txt file
body: <p>I've been working on a project and I need to print an array of words to a text file on individual lines with the positon it is in the array. I have used streamwriters in the past so I was planning on using it again for this however I can't seem to get it to write the text file. Below is the code:</p>
  
  <pre><code> public partial class Form2 : Form
  {
      string sentence;
      String[] words;
      int a;
      bool wordAppear;
      string textbox2;
      string path;
      public Form2()
      {
          InitializeComponent();
          path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
      }
  
      private void btn1_Click(object sender, EventArgs e)
      {
          sentence = txt1.Text.ToLower();
          words = sentence.Split();
          a = words.Length;
          MessageBox.Show("Number of Words: " + a);
          StreamWriter sw = new StreamWriter(path + @"\file1000.txt");
          for (int i=0; i &lt; a; i++)
          {
              sw.WriteLine(words[i] + " " + i+1);
          }
      }
  }
  </code></pre>
  
  <p>Part of my task involves listing the order that the word first appears so for example if the sentence was 'I have twenty men with twenty hammers' the order would be 1 2 3 4 5 3 6 so if anybody has any ideas on how to do this please could you suggest them</p>