/// <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}"); } } }
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); } } } }
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; } } } }
private void guardarToolStripMenuItem_Click(object sender, EventArgs e) { PuntoTxt txt = new PuntoTxt(); PuntoDat dat = new PuntoDat(); string texto = this.richTextBox1.Text.Replace("\n", "\r\n"); try { if (this._lastFilePath.EndsWith(".txt")) { txt.Guardar(this._lastFilePath, texto); } else { dat.Contenido = texto; dat.Guardar(this._lastFilePath, dat); } } catch (ArchivoIncorrectoException) { this.guardarComoToolStripMenuItem_Click(this.guardarComoToolStripMenuItem, new EventArgs()); } catch (Exception) { MessageBox.Show("FATAL ERROR"); } }
private void GuardarComo() { SaveFileDialog guardar = new SaveFileDialog(); guardar.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); guardar.Filter = "Archivos de texto (*.txt)|*.txt|Archivos de datos (*.dat)|*.dat"; if (guardar.ShowDialog() == DialogResult.OK) { this.path = guardar.FileName; if (Path.GetExtension(this.path) == ".txt") { PuntoTxt texto1 = new PuntoTxt(); texto1.GuardarComo(this.path, this.richTextBox1.Text); } else { PuntoDat texto = new PuntoDat(); texto.Contenido = this.richTextBox1.Text; texto.GuardarComo(this.path, texto); } } }
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); } }
private void guardarComoToolStripMenuItem_Click(object sender, EventArgs e) { string filePath; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { filePath = saveFileDialog.FileName; try { if (Path.GetExtension(filePath) == ".txt") { PuntoTxt ptxt = new PuntoTxt(); ptxt.GuardarComo(filePath, richTextBox.Text); } else { PuntoDat pdat = new PuntoDat(); pdat.Contenido = richTextBox.Text; pdat.GuardarComo(filePath, pdat); } ultimoArchivoAbierto = filePath; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void GuardarArchivo(string texto) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { this.path = saveFileDialog.FileName; this.tipoArchivo = saveFileDialog.FilterIndex; switch (this.tipoArchivo) { case 1: { PuntoTxt archivo = new PuntoTxt(); archivo.GuardarComo(this.path, this.rchtbCajaDetexto.Text); break; } case 2: { PuntoDat archivo = new PuntoDat(); archivo.Contenido = this.rchtbCajaDetexto.Text; archivo.GuardarComo(this.path, archivo); break; } } } }
private void guardarToolStripMenuItem_Click(object sender, EventArgs e) { if (!(string.IsNullOrWhiteSpace(this.path))) { switch (this.tipoArchivo) { case 1: { PuntoTxt archivo = new PuntoTxt(); archivo.Guardar(this.path, this.rchtbCajaDetexto.Text); break; } case 2: { PuntoDat archivo = new PuntoDat(); archivo.Contenido = this.rchtbCajaDetexto.Text; archivo.Guardar(this.path, archivo); break; } } } else { this.GuardarArchivo(this.rchtbCajaDetexto.Text); } }
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 guardarComoToolStripMenuItem_Click(object sender, EventArgs e) { PuntoTxt txt = new PuntoTxt(); PuntoDat dat = new PuntoDat(); string texto = this.richTextBox1.Text.Replace("\n", "\r\n"); if (TextEditor._saveFileMenu.ShowDialog() == DialogResult.OK) { this._lastFilePath = TextEditor._saveFileMenu.FileName; try { if (this._lastFilePath.EndsWith(".txt")) { txt.GuardarComo(this._lastFilePath, texto); } else { dat.Contenido = texto; dat.GuardarComo(this._lastFilePath, dat); } } catch (Exception) { MessageBox.Show("FATAL ERROR"); } } }
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"); } } }
private void guardarToolStripMenuItem_Click(object sender, EventArgs e) { string datos; PuntoDat archivoDat; PuntoTxt archivoTxt; archivoDat = new PuntoDat(); archivoTxt = new PuntoTxt(); datos = rtbEditorDeTexto.Text; if (this.PathArchivo is null) { this.guardarComoToolStripMenuItem_Click(sender, e); } else { switch (Path.GetExtension(this.PathArchivo)) { case ".txt": archivoTxt.GuardarComo(this.PathArchivo, datos); break; case ".dat": //Guardo el texto en la propiedad contenido archivoDat.Contenido = datos; //Le paso el objeto PuntoDat con el texto cargado archivoDat.GuardarComo(this.PathArchivo, archivoDat); break; } } }
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; } } }
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; } } }
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); } }
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"; }
private void binarioToolStripMenuItem1_Click(object sender, EventArgs e) { sfdGuardar.Filter = "Archivo Datos|*.dat"; if (sfdGuardar.ShowDialog() == DialogResult.OK) { this.path = sfdGuardar.FileName; } else { return; } PuntoDat archivo = new PuntoDat(); archivo.Contenido = rtbEditor.Text; archivo.Guardar(path, archivo); this.tipo = "binario"; }
private void guardar() { switch (Path.GetExtension(path)) { case ".txt": new PuntoTxt().Guardar(path, mainRichTextBox.Text); break; case ".dat": PuntoDat puntoDat = new PuntoDat(); puntoDat.Contenido = mainRichTextBox.Text; puntoDat.Guardar(path, puntoDat); break; //case ".xml": // archivoXml.Guardar(nombreArchivo, richTextBox1.Text); // break; } }
private void abrirToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat|All files (*.*)|*.*"; ofd.ShowDialog(); rutaArchivoActual = ofd.FileName; if (Path.GetExtension(rutaArchivoActual) == ".txt") { PuntoTxt stream = new PuntoTxt(); rtb_texto.Text = stream.Leer(rutaArchivoActual); } if (Path.GetExtension(rutaArchivoActual) == ".dat") { PuntoDat stream = new PuntoDat().Leer(rutaArchivoActual); rtb_texto.Text = stream.Contenido; } }
private void guargarToolStripMenuItem_Click(object sender, EventArgs e) { switch (this.tipo) { case "binario": PuntoDat dat = new PuntoDat(); dat.Contenido = rtbEditor.Text; dat.Guardar(path, dat); break; case "texto": PuntoTxt txt = new PuntoTxt(); txt.Guardar(path, rtbEditor.Text); break; default: break; } }
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; } } }
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; } }
private void guardarComoToolStripMenuItem_Click(object sender, EventArgs e) { guardarArchivo = new SaveFileDialog(); guardarArchivo.Filter = "txt files(*.txt)|*.txt|dat files(*.dat)|*.dat"; if (guardarArchivo.ShowDialog() == DialogResult.OK) { string ruta = guardarArchivo.FileName; if (Path.GetExtension(ruta) == ".txt") { txt = new PuntoTxt(); txt.GuardarComo(ruta, richTextBox1.Text); } else { dat = new PuntoDat(); dat.Contenido = richTextBox1.Text; dat.GuardarComo(ruta, dat); } } }
private void guardarComoCtrlMayúsSToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat|All files (*.*)|*.*"; sfd.ShowDialog(); rutaArchivoActual = sfd.FileName; if (Path.GetExtension(rutaArchivoActual) == ".txt") { PuntoTxt stream = new PuntoTxt(); stream.Guardar(rutaArchivoActual, rtb_texto.Text); } if (Path.GetExtension(rutaArchivoActual) == ".dat") { PuntoDat stream = new PuntoDat(); stream.Contenido = rtb_texto.Text; stream.Guardar(rutaArchivoActual, stream); } }
private void guardarToolStripMenuItem_Click(object sender, EventArgs e) { if (ruta == null) { guardarComoToolStripMenuItem_Click(sender, e); } else { if (Path.GetExtension(ruta) == ".txt") { PuntoTxt guardarTxt = new PuntoTxt(); bool aux = guardarTxt.Guardar(ruta, richTextBox1.Text); } else if (Path.GetExtension(ruta) == ".dat") { PuntoDat guardarDat = new PuntoDat(); guardarDat.Contenido = richTextBox1.Text; bool aux2 = guardarDat.Guardar(ruta, guardarDat); } } }
public void GuardarComo() { SaveFileDialog dialog = new SaveFileDialog(); //debería usar using? 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 puntoTxt = new PuntoTxt(); puntoTxt.GuardarComo(this.path, richTextBox1.Text); } else if (Path.GetExtension(this.path) == ".dat") { PuntoDat puntoDat = new PuntoDat(); puntoDat.Contenido = richTextBox1.Text; puntoDat.GuardarComo(this.path, puntoDat); } } }
private void guardarCtrlSToolStripMenuItem_Click(object sender, EventArgs e) { if (rutaArchivoActual == null) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat|All files (*.*)|*.*"; sfd.ShowDialog(); rutaArchivoActual = sfd.FileName; if (Path.GetExtension(rutaArchivoActual) == ".txt") { PuntoTxt stream = new PuntoTxt(); stream.Guardar(rutaArchivoActual, rtb_texto.Text); this.tssl_numberOfChars.Text = string.Format("caracteres: {0} - {1}", rtb_texto.Text.Length, this.rutaArchivoActual); } if (Path.GetExtension(rutaArchivoActual) == ".dat") { PuntoDat stream = new PuntoDat(); stream.Contenido = rtb_texto.Text; stream.Guardar(rutaArchivoActual, stream); this.tssl_numberOfChars.Text = string.Format("caracteres: {0} - {1}", rtb_texto.Text.Length, this.rutaArchivoActual); } } else { if (Path.GetExtension(rutaArchivoActual) == ".txt") { PuntoTxt stream = new PuntoTxt(); stream.Guardar(rutaArchivoActual, rtb_texto.Text); } if (Path.GetExtension(rutaArchivoActual) == ".dat") { PuntoDat stream = new PuntoDat(); stream.Contenido = rtb_texto.Text; stream.Guardar(rutaArchivoActual, stream); } } }
private void guardarComo() { if (saveFileDialog.ShowDialog() == DialogResult.OK) { path = saveFileDialog.FileName; switch (saveFileDialog.FilterIndex) { case 1: new PuntoTxt().GuardarComo(path, mainRichTextBox.Text); break; case 2: PuntoDat puntoDat = new PuntoDat(); puntoDat.Contenido = mainRichTextBox.Text; puntoDat.GuardarComo(path, puntoDat); break; //case 3: // archivoXml.GuardarComo(ventana.FileName, richTextBox1.Text); // break; } } }
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; } } }