Manipulación de archivos de texto

Manipulación de archivos de texto.

Agregar el código necesario que permita abrir un archivo de texto ubicado en el escritorio llamado info.txt (crearlo inicialmente y llenarlo con la fecha actual), muestre su contenido y permita agregar una nueva línea de texto con su nombre completo.

Interfaz gráfica.


Código fuente.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;


namespace ManipulaArchivoTexto

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void btnArchi_Click(object sender, EventArgs e)

        {

            TextWriter archivo = new                                                                       StreamWriter("C:\\Users\\Carlos\\Desktop\\info.txt");

            archivo.WriteLine(DateTime.Now.ToString());   

            archivo.Close();

        }

        private void btnConsul_Click(object sender, EventArgs e)

        {

            string ruta = @"C:\\Users\\Carlos\\Desktop\\info.txt";

            string linea = "";

            StreamReader archivo = new StreamReader(ruta);           

            linea = archivo.ReadToEnd();

                txtInforArchi.Text = linea;

            archivo.Close();           

        }

        private void btnInsertInfo_Click(object sender, EventArgs e)

        {

            string ruta = @"C:\\Users\\Carlos\\Desktop\\info.txt";

            string texto = txtinfoalmacenar.Text;

            StreamWriter archivo = new StreamWriter(ruta, true);            

            archivo.WriteLine(texto);

            archivo.Close();            

        }

        private void btnSalir_Click(object sender, EventArgs e)

        {

            this.Close();

        }

    }

}

Comentarios

Entradas populares de este blog

Descripción de los sistemas numéricos y sus conversiones.

Diagrama sistema liquidación de nómina.

Análisis BDOO y BDD