title: Accessing string from an html template class
body: <p>I'm trying to access a certain variable from another class, however I'm not able to do so. I have two buttons - the first button sets token to an html template file. The second should generate the file. The first button calls the class. The second button should call the string from the class for generation.</p>
  
  <p>My first button is as follows:</p>
  
  <pre><code>private void btnTemplate_Click(object sender, EventArgs e)
      {
          if ((txtTitle.Text == "") &amp;&amp; (txtSku.Text == "") &amp;&amp; (txtPrice.Text == "") &amp;&amp; (txtDesc.Text == "") &amp;&amp; (txtImg.Text == ""))
          {
              MessageBox.Show("No row selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          else
          {
              OpenFileDialog SetData = new OpenFileDialog();
              SetData.Filter = "HTML|*.html;";
              GlobalVar.setPath = "C:\\genHtml.html";
              var result = SetData.ShowDialog();
              DataSet ds = new DataSet();
  
              if (result == DialogResult.OK)
              {
                  string fileName = SetData.FileName;
                  var template = new HtmlTemplate(@SetData.FileName);
                  var output = template.Render(new
                  {
                      TITLE = txtTitle.Text,
                      SKU = txtSku.Text,
                      PRICE = txtPrice.Text,
                      DESC = txtDesc.Text,
                      IMAGE = txtImg.Text
                  });
                  File.WriteAllText(@GlobalVar.setPath, output);
              }
          }
      }
  </code></pre>
  
  <p>My second button:</p>
  
  <pre><code>private void btnGenerate_Click(object sender, EventArgs e)
      {
          try
          {
  
  
              System.Diagnostics.Process.Start(GlobalVar.setPath);
          }
          catch
          {
              MessageBox.Show("Please select a template first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  </code></pre>
  
  <p>I get an error with the string output. How can I call string 'output' for the second button?</p>
  
  <p>My class is as follows:</p>
  
  <pre><code>class HtmlTemplate
  {
      private string _html;
  
      public HtmlTemplate(string templatePath)
      {
          using (var reader = new StreamReader(templatePath))
              _html = reader.ReadToEnd();
      }
  
      public string Render(object values)
      {
          string output = _html;
          foreach (var p in values.GetType().GetProperties())
              output = output.Replace("[" + p.Name + "]", (p.GetValue(values, null) as string) ?? string.Empty);
          return output;
      }
  }
  </code></pre>