title: how to use a variable from other context in c#
body: <p>I just need to know on how to use variable from other blocks or context(or whatever they call it)...</p>
  
  <p>I was trying to create an app installer for windows 10 using powershell but i'm just a beginner for c#...</p>
  
  <p>I have 2 Buttons the browse and install, I declare the location of the file in the browse button's block and I was trying to use that variable in the install button's context.</p>
  
  <p>But all I got is "The name "appFile" does not exist in the current context."</p>
  
  <p>Here's my code:</p>
  
  <pre><code>   private void button3_Click(object sender, EventArgs e)
      {
          MessageBox.Show("Created by Carlos Miguel Salamat","Windows App Installer");
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
  
          OpenFileDialog file = new OpenFileDialog();
          file.Title = "Choose Package File";
          file.InitialDirectory = @"c:\";
          file.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
          file.FilterIndex = 2;
          file.RestoreDirectory = true;
          if (file.ShowDialog() == DialogResult.OK)
          {
              textBox1.Text = file.FileName;
  
             string appFile = file.FileName;
          }
      }
      private void button2_Click(object sender, EventArgs e)
      {
          string strCmdText;
          strCmdText = "powershell.exe add-appxpackage";
          System.Diagnostics.Process.Start("CMD.exe", strCmdText, appFile);
      }
    }
  }
  </code></pre>
  
  <p>`</p>