title: How to write text into a word file using C#, .NET
body: <p>I am trying to write and append some text to a word file using c#, however, I am unable to get expected results. Could you please help me out of this ?</p>
  <p><strong>Below is my code-</strong></p>
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
      using System.IO;
      
      namespace WFA1
      {
          public partial class Form2 : Form
          {
              public Form2()
              {
                  InitializeComponent();
              }
      
              private void button1_Click(object sender, EventArgs e)
              {
                  //FileStream F = new FileStream(&quot;testdoc2.docx&quot;, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                  Console.WriteLine(&quot;Sourav&quot;);           
                  string filename = @&quot;C:\\Desktop\\myfile.docx&quot;;
                  Console.WriteLine(filename);
                  try
                  {
                      using (FileStream fs = File.OpenWrite(filename))
                      {
                          Byte[] content = new UTF8Encoding(true).GetBytes(&quot;Hello I am learning C#&quot;);
                          fs.Write(content, 0, content.Length);
                      }
                  }
                  catch (Exception Ex)
                  {
                      Console.Write(e.ToString());
                  }
                  
      
      
              }
          }
      }
  </code></pre>
  <p>The above code is a windows form application code behind. I have use FileStream class to write data. However I am facing below issues :-</p>
  <blockquote>
  <ol>
  <li>No file is getting created</li>
  <li>Code keeps on running until I stop it manually.</li>
  </ol>
  </blockquote>
  <p>Hence, I tried the below approach too, and I was able to write text to the file.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  using Microsoft.Office.Interop.Word;
  
  namespace WFA1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
              Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(&quot;C:\\Users\\SS5014874\\Desktop\\testdoc1.docx&quot;);
              object missing = System.Reflection.Missing.Value;
              //string s = &quot;Hi&quot;;
              //Console.WriteLine(s);               
              doc.Content.Text = textBox1.Text.ToString();
              doc.Save();
              doc.Close(ref missing);
  
              app.Quit(ref missing);
          }
      }
  }
  </code></pre>
  <p>However, still I did not get expected results. below are my issues:-</p>
  <blockquote>
  <ol>
  <li>Unable to append any text. Please let me know how to append using this approach. is there any method we can call to append texts.</li>
  <li>Even though I have used Quit method, application is not quitting, until I quit manually.</li>
  </ol>
  </blockquote>
  <p>Also, where can I find the list of methods of class <code>Microsoft.Office.Interop.Word</code></p>
  <p>Please let me know for any other information.</p>