Example #1
0
        private void btnBrowser_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "txt files (*.txt)|*.txt",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    txtFilePath.Text = openFileDialog1.FileName;
                    var sr = new StreamReader(openFileDialog1.FileName);
                    txtSrc.Text  = sr.ReadToEnd();
                    txtDist.Text = Parsing.ConvertTxtToJson(txtFilePath.Text);
                }
                catch (SecurityException ex)
                {
                    MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
                                    $"Details:\n\n{ex.StackTrace}");
                }
            }
        }