예제 #1
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Title            = "Open Text File";
            openFile.Filter           = "TXT files|*.txt|DAT files|*.dat";
            openFile.InitialDirectory = @"C:\";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                ruta = openFile.FileName.ToString();
                switch (openFile.FilterIndex)
                {
                case 1:     //selected .txt
                    PuntoTxt leerTxt = new PuntoTxt();
                    richTextBox1.Text = leerTxt.Leer(openFile.FileName);
                    break;

                case 2:     //selected .dat
                    PuntoDat leerDat = new PuntoDat();
                    leerDat           = leerDat.Leer(openFile.FileName);
                    richTextBox1.Text = leerDat.Contenido;
                    break;
                }
            }
        }
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\Users\Nacho\source\repos\Ejercicio 58";                                   //ruta de inicio, desp puedo elegir la que quiera
            openFileDialog.Filter           = "all files (*.*)|*.*|txt files (*.txt)|*.txt|archivos de datos (*.dat)|*.dat"; //tipo de archivo que puedo abrir

            try
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    path = openFileDialog.FileName;
                    if (Path.GetExtension(path) == ".txt")
                    {
                        richTextBox.Text = puntoTxt.Leer(path);
                    }
                    else if (Path.GetExtension(path) == ".dat")
                    {
                        puntoDat         = puntoDat.Leer(path);
                        richTextBox.Text = puntoDat.Contenido;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.path        = openFileDialog.FileName;
                this.tipoArchivo = openFileDialog.FilterIndex;
                switch (this.tipoArchivo)
                {
                case 1:
                {
                    PuntoTxt archivo = new PuntoTxt();
                    this.rchtbCajaDetexto.Text = archivo.Leer(this.path);
                    break;
                }

                case 2:
                {
                    PuntoDat archivo = new PuntoDat();
                    this.rchtbCajaDetexto.Text = (archivo.Leer(this.path)).Contenido;
                    break;
                }
                }
            }
        }
예제 #4
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string fileContent = string.Empty;
            string filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = openFileDialog.FileName;
                    try
                    {
                        if (Path.GetExtension(filePath) == ".txt")
                        {
                            PuntoTxt ptxt = new PuntoTxt();
                            richTextBox.Text = ptxt.Leer(filePath);
                        }
                        else
                        {
                            PuntoDat pdat = new PuntoDat();
                            pdat             = pdat.Leer(filePath);
                            richTextBox.Text = pdat.Contenido;
                        }
                        ultimoArchivoAbierto = filePath;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
예제 #5
0
 /// <summary>
 /// EventHandler of Open Button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
 {
     openFileDialog1        = new OpenFileDialog();
     openFileDialog1.Title  = "Select a File";
     openFileDialog1.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat|All files (*.*)|*.*";
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string file = openFileDialog1.FileName;
         lastFilePath = file;
         MessageBox.Show($"{lastFilePath}");
         try {
             if (Path.GetExtension(lastFilePath) == ".txt")
             {
                 rtbText.Text = txtManager.Leer(lastFilePath);
             }
             else if (Path.GetExtension(lastFilePath) == ".dat")
             {
                 datManager   = datManager.Leer(lastFilePath);
                 rtbText.Text = datManager.Contenido;
             }
         } catch (ArchivoIncorrectoException ai) {
             MessageBox.Show($"Excepcion: {ai.Message}");
         }
     }
 }
예제 #6
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //StreamReader sr;

            PuntoTxt archivoTxt = new PuntoTxt();
            PuntoDat archivoDat = new PuntoDat();


            //Muestra una ventana para seleccionar el archivo
            OpenFileDialog abrir = new OpenFileDialog();

            abrir.Filter = "Archivos de texto (*.txt)|*.txt|Archivos de datos (*.dat)|*.dat";

            if (abrir.ShowDialog() == DialogResult.OK)
            {
                this.PathArchivo = abrir.FileName;

                switch (abrir.FilterIndex)
                {
                case 1:    //texto
                    rtbEditorDeTexto.Text = archivoTxt.Leer(this.PathArchivo);
                    break;

                case 2:    //binario
                    //Guardo el .dat en una variable
                    archivoDat = archivoDat.Leer(this.PathArchivo);
                    //Leo el texto que está en la propiedad contenido
                    rtbEditorDeTexto.Text = archivoDat.Contenido;
                    break;
                }
            }
        }
예제 #7
0
        private void stripAbrir_OnClick(object sender, EventArgs e)
        {
            OpenFileDialog abrir = new OpenFileDialog();

            abrir.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            abrir.Filter           = "Archivos de texto (*.txt)|*.txt|Archivos de datos (*.dat)|*.dat";

            if (abrir.ShowDialog() == DialogResult.OK)
            {
                this.path = abrir.FileName;

                if (Path.GetExtension(this.path) == ".txt")
                {
                    PuntoTxt texto1 = new PuntoTxt();

                    this.richTextBox1.Text = texto1.Leer(this.path);
                }
                else
                {
                    PuntoDat texto = new PuntoDat();

                    this.richTextBox1.Text = texto.Leer(this.path).Contenido;
                }
            }
        }
예제 #8
0
파일: Form1.cs 프로젝트: 413831/C_sharp_NET
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ventana = new OpenFileDialog();

            ventana.Filter = "Archivos de texto(.txt)|*.txt|Archivos de datos (.dat)|*.dat|Archivos XML(.xml)|*.xml";

            if (ventana.ShowDialog() == DialogResult.OK)
            {
                nombreArchivo = ventana.FileName;
                MessageBox.Show(ventana.FilterIndex.ToString());

                switch (ventana.FilterIndex)
                {
                case 1:
                    richTextBox1.Text = archivoTxt.Leer(ventana.FileName);
                    break;

                case 2:
                    archivoDat        = archivoDat.Leer(ventana.FileName); //REVISAR
                    richTextBox1.Text = archivoDat.Contenido;
                    break;

                case 3:
                    richTextBox1.Text = archivoXml.Leer(ventana.FileName);     //REVISAR
                    break;
                }
            }
            else
            {
                this.guardarComoToolStripMenuItem1_Click(sender, e);
            }
        }
예제 #9
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Lectura del archivo.
            PuntoTxt txt = new PuntoTxt();
            PuntoDat dat = new PuntoDat();

            if (TextEditor._openFileMenu.ShowDialog() == DialogResult.OK)
            {
                this._lastFilePath = TextEditor._openFileMenu.FileName;
                try
                {
                    if (this._lastFilePath.EndsWith(".txt"))
                    {
                        this.richTextBox1.Text = txt.Leer(this._lastFilePath);
                    }
                    else
                    {
                        this.richTextBox1.Text = dat.Leer(this._lastFilePath).Contenido;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("FATAL ERROR");
                }
            }
        }
예제 #10
0
        private void binarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ofdAbrir.ShowDialog() == DialogResult.OK)
            {
                this.path = ofdAbrir.FileName;
            }
            else
            {
                return;
            }
            PuntoDat archivo = new PuntoDat();

            archivo        = archivo.Leer(path);
            rtbEditor.Text = archivo.Contenido;
            this.tipo      = "binario";
        }
예제 #11
0
        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ofd.Filter = "Archivos de texto (*.txt)|*.txt|Archivos de datos (*.dat)|*.dat";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                switch (ofd.FilterIndex)
                {
                case 0:

                    rtbTexto.Text = txt.Leer(ofd.FileName);
                    break;

                case 1:
                    dat           = dat.Leer(ofd.FileName);
                    rtbTexto.Text = dat.Contenido;
                    break;
                }
                guardarToolStripMenuItem.Enabled = true;
            }
        }
예제 #12
0
 private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
 {
     abrirArchivo        = new OpenFileDialog();
     abrirArchivo.Filter = "txt files(*.txt)|*.txt|dat files(*.dat)|*.dat";
     if (abrirArchivo.ShowDialog() == DialogResult.OK)
     {
         string ruta = abrirArchivo.FileName;
         if (Path.GetExtension(ruta) == ".txt")
         {
             txt = new PuntoTxt();
             richTextBox1.Text = txt.Leer(ruta);
         }
         else
         {
             dat = new PuntoDat();
             dat = dat.Leer(ruta);
             richTextBox1.Text = dat.Contenido;
         }
     }
 }
예제 #13
0
        private void abrirMenuStripItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                path = openFileDialog.FileName;
                switch (openFileDialog.FilterIndex)
                {
                case 1:
                    mainRichTextBox.Text = new PuntoTxt().Leer(openFileDialog.FileName);
                    break;

                case 2:
                    PuntoDat puntoDat = new PuntoDat();
                    puntoDat             = puntoDat.Leer(openFileDialog.FileName);
                    mainRichTextBox.Text = puntoDat.Contenido;
                    break;
                    //case 3:
                    //    richTextBox1.Text = archivoXml.Leer(ventana.FileName); //REVISAR
                    //    break;
                }
            }
        }
예제 #14
0
        public void Abrir()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = (this.path == null) ? AppDomain.CurrentDomain.BaseDirectory : this.path;
            dialog.Filter           = "Archivos de texto (.txt)|*.txt|Archivos de datos (.dat)|*.dat";

            if (DialogResult.OK == dialog.ShowDialog())  //si click cancel no entra
            {
                this.path = dialog.FileName;
                if (Path.GetExtension(this.path) == ".txt")
                {
                    PuntoTxt puntoTxt = new PuntoTxt();
                    richTextBox1.Text = puntoTxt.Leer(this.path);
                }
                else if (Path.GetExtension(this.path) == ".dat")
                {
                    PuntoDat puntoDat = new PuntoDat();
                    puntoDat          = puntoDat.Leer(this.path);
                    richTextBox1.Text = puntoDat.Contenido;
                }
            }
        }
예제 #15
0
        public void Abrir()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = (this.path == null) ? AppDomain.CurrentDomain.BaseDirectory : this.path;
            dialog.Filter           = "Archivos de texto (.txt)|*.txt|Archivos de datos (.dat)|*.dat";

            if (DialogResult.OK == dialog.ShowDialog())
            {
                this.path = dialog.FileName;
                if (Path.GetExtension(this.path) == ".txt")
                {
                    PuntoTxt texto = new PuntoTxt();
                    rtbTexto.Text = texto.Leer(this.path);
                }
                else if (Path.GetExtension(this.path) == ".dat")
                {
                    PuntoDat binario = new PuntoDat();
                    binario       = binario.Leer(this.path);
                    rtbTexto.Text = binario.Contenido;
                }
            }
        }
예제 #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("[1] Abrir\n[2] Guardar");
            string ruta = @"D:\";

            switch (Int32.Parse(Console.ReadLine()))
            {
            case 1:

                PuntoDat leerDat = new PuntoDat();
                leerDat = leerDat.Leer(ruta);
                Console.WriteLine(leerDat.Contenido);
                break;

            case 2:
                PuntoDat guardarDat = new PuntoDat();
                guardarDat.Contenido = "xxx";
                bool aux2 = guardarDat.Guardar(ruta, guardarDat);

                Console.WriteLine("Guardado!");
                break;
            }
            Console.ReadKey();
        }