Example #1
0
        private void AbrirArquivoOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                caminho = DialogoAbrir.FileName;

                NomeArquivo.Text = DialogoAbrir.FileName;
                FileInfo arquivo = new FileInfo(DialogoAbrir.FileName);
                Conteudo.Text = "";

                TextReader reader = null;
                reader = arquivo.OpenText();

                string line = reader.ReadLine();
                while (line != null)
                {
                    Conteudo.Text += line + "\n";
                    line           = reader.ReadLine();
                }
                reader.Close();
                flag             = false;
                Salvar.IsEnabled = false;

                throw new System.ArgumentException("Teste", "original");
            }
            catch (Exception ex)
            {
                AppManager.AppExceptionsTxt exc = new AppExceptionsTxt();
                exc.SalvarExcecao(ex);
            }
        }
Example #2
0
        // lê o texto do arquivo e atribui ao controle "Conteudo"
        private void AbrirArquivoOk(Object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                // throw new System.ArgumentException("Parameter cannot be null", "original");

                NomeArquivo.Text = DialogoAbrir.FileName;
                caminho          = DialogoAbrir.FileName;
                FileInfo   info   = new FileInfo(DialogoAbrir.FileName);
                TextReader reader = null;

                Conteudo.Text = "";

                reader = info.OpenText();

                // Lê linha a linha do arquivo e colocar ao controle "Conteudo.Text"

                string line = reader.ReadLine();
                while (line != null)
                {
                    Conteudo.Text += line;
                    line           = reader.ReadLine();
                }
                flag = false;
                reader.Close(); // O SISTEMA OPERACIONAL LIBERA O ARQUIVO
            }
            catch (Exception ex)
            {
                AppExceptionsTxt appex = new AppExceptionsTxt();
                appex.PathSaveFile = "";
                appex.SaveException(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
 protected void SalvarArquivo()
 {
     try
     {
         if (caminho.Trim() == "")
         {
             DialogoSalvar.ShowDialog();
         }
         else
         {
             File.WriteAllText(caminho, Conteudo.Text, Encoding.UTF8);
             flag                 = false;
             Salvar.IsEnabled     = false;
             SalvarComo.IsEnabled = false;
         }
     }
     catch (Exception ex)
     {
         AppManager.AppExceptionsTxt exc = new AppExceptionsTxt();
         exc.PathSaveException = "C:";
         exc.SalvarExcecao(ex, caminho);
     }
 }