示例#1
0
        private void Open_FileBtn_Click(object sender, EventArgs e)
        {
            if (Jarvis.State == SynthesizerState.Speaking)
            {
                Jarvis.SpeakAsyncCancelAll();
            }
            Readtxt.Clear();
            Jarvis.SpeakAsync("choose a text file from your, drives");

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //Filter for type of the file we are going to open
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|rtf files (*.rtf)|*.rtf|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    //FileNames Gets the file names of all selected files in the dialog box
                    string strfilename = openFileDialog1.FileName;
                    //Here we are using System.IO class to reads the lines of a file
                    string filetext = File.ReadAllText(strfilename);
                    //than we are going to pass the filetxt to over textbox which is Readtxt.Text
                    Readtxt.Text = filetext;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
示例#2
0
        private void OpenBtn_Click(object sender, EventArgs e)
        {
            if (martha.State == SynthesizerState.Speaking)
            {
                martha.SpeakAsyncCancelAll();
            }
            Readtxt.Clear();
            martha.SpeakAsync(" sir please chose a text file form your derives");
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "txt files (*.txt)|*.txt|rtf files (*.rtf)|*.rtf|All files(*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string strfilename = openFileDialog1.FileName;
                    string filetext    = File.ReadAllText(strfilename);
                    Readtxt.Text = filetext;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: could not read the file from disk:" + ex.Message);
                }
            }
        }