Folder Browser Dialog with Environment
<p>I created an app for my dad. It's just a simple dictation program. The thing is when he installed it on his computer it stalled and said the general access denied error. </p>

<p>The first time it gave the error I used <code>SaveFileDialog sfd = new SaveFileDialog()</code> then added the usually 'if statement" to make sure the dialog was ok. However the app had an access file denied. </p>

<p>I did the same thing with <code>Environment.GetFolder</code> and it installed on his computer to the location and ran fine. However, when I use the <code>saveFileDialog1</code> and <code>openFileDialog1</code> out of the tool box it does not save or open a txt document.</p>

<p>It works on my laptop and not his. Could this be due to an error in the code vs his computer. Also what is the correct way to use the <code>Environement.GetFolder</code> with the <code>SaveFileDialog</code>.</p>

<p>I can also post the full code to the program if needed.</p>

<pre><code>  private void lblOpenFile_Click(object sender, EventArgs e)
    {

        OpenFileDialog open = new OpenFileDialog();
        open.Title = "Open File";
        open.Filter = "Text Files (*txt) | *.txt";

        if (open.ShowDialog() == DialogResult.OK)
        {
            StreamReader read = new StreamReader(File.OpenRead(open.FileName));

            txtTextBox.Text = read.ReadToEnd();
            read.Dispose();
        }
    }

    private void lblSaveFile_Click(object sender, EventArgs e)
    {

        SaveFileDialog save = new SaveFileDialog();
        save.Title = "Save File";
        save.Filter = "Text Files (*txt) | *.txt";

        if (save.ShowDialog() == DialogResult.OK)
        {
            StreamWriter write = new StreamWriter(File.Create(save.FileName));

            write.Write(txtTextBox.Text);
            write.Dispose();
        }
    }
</code></pre>

<p>This is the <code>Enviroment</code> i used on my screen recorder. i when i click save it brings up a dialog box i put in the file name press save and it does nothing. It saves the file but not as i specified. So i am trying to merge the above and below codes. The above code does not grant access however the below does</p>

<pre><code>string OutputPath;    

OutputPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos) + @"\\IvanSoft Desktop Recorder" + saveFileDialog1;


private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
    {
       string fileName = saveFileDialog1.FileName;
        fileName = "Tutorial";       
    }
</code></pre>

<p>the whole code to the program </p>

<pre><code>using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Speech.Recognition;
using System.Threading;

namespace AGM_Speech
{
    public partial class Form1 : Form
    {
        public SpeechRecognitionEngine recognizer;
        public Grammar grammar;
        public Thread RecThread;
        public Boolean RecognizerState = true;

        public Form1()
        {
            InitializeComponent();
        }

        private void lblAbout_Click(object sender, EventArgs e)
        {
            this.Hide();
            About about = new About();
            about.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GrammarBuilder builder = new GrammarBuilder();
            builder.AppendDictation();


            grammar = new Grammar(builder);
            recognizer = new SpeechRecognitionEngine();
            recognizer.LoadGrammarAsync(grammar);
            recognizer.SetInputToDefaultAudioDevice();

            recognizer.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(recognizer_SpeechRecognized);

            RecognizerState = true;
            RecThread = new Thread(new ThreadStart(RecThreadFunction));
            RecThread.Start();
        }

        private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {

            if (!RecognizerState)
                return;

            this.Invoke((MethodInvoker)delegate
            {
                txtTextBox.Text += (e.Result.Text.ToLower() + " ");
                txtTextBox.SelectionStart = txtTextBox.Text.Length - 0;
                txtTextBox.SelectionLength = 0;

            });
        }

        public void RecThreadFunction()
        {
            while (true)
            {
                try
                {
                    recognizer.RecognizeAsync();
                }
                catch
                {

                }


            }
        }

        private void lblStartSpeech_Click(object sender, EventArgs e)
        {
            RecognizerState = true;

        }

        private void lblStopSpeech_Click(object sender, EventArgs e)
        {
            RecognizerState = false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            RecThread.Abort();
            RecThread = null;
            grammar = null;
            recognizer.UnloadAllGrammars();
            recognizer.Dispose();


        }

        private void lblOpenFile_Click(object sender, EventArgs e)
        {

            string open = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            StreamReader reader = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));


        }

        private void lblSaveFile_Click(object sender, EventArgs e)
        {

            SaveFileDialog save = new SaveFileDialog();
            save.Title = "Save File";
            save.Filter = "Text Files (*txt) | *.txt";

            if (save.ShowDialog() == DialogResult.OK)
            {
                StreamWriter write = new StreamWriter(File.Create(save.FileName));

                write.Write(txtTextBox.Text);
                write.Dispose();
            }
        }




        private void txtSearch_Click(object sender, EventArgs e)
        {
            txtSearch.Clear();
            lblGo_Click(null, null);
        }

        private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)ConsoleKey.Enter)
            {
                lblGo_Click(null, null);

            }
        }

        private void lblGo_Click(object sender, EventArgs e)
        {
            int index = 0;
            String temp = txtTextBox.Text;
            txtTextBox.Text = "";
            txtTextBox.Text = temp;

            while (index &lt;= txtTextBox.Text.LastIndexOf(txtSearch.Text))
            {
                txtTextBox.Find(txtSearch.Text, index, txtTextBox.TextLength, RichTextBoxFinds.None);
                txtTextBox.SelectionColor = Color.YellowGreen;
                index = txtTextBox.Text.IndexOf(txtSearch.Text, index) + 1;
            }
        }
    }
}
</code></pre>