ATENCIÓN AL CLIENTE: +34 923 199 148

Leer un fichero de texto en un Pocket Pc

En el siguiente ejemplo, podemos ver cómo leer un fichero de texto en un Pocket Pc.
Tenemos una caja de texto y al pulsar el botón cmdLeer, podremos elegir el nombre del fichero que queremos leer y su contenido será mostrado en la caja de texto anterior.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SmartDeviceProject1
{
   public partial class LectorFichero : Form
   {
      public LectorFichero()
      {
         InitializeComponent();
      }

      private void cmdLeer_Click(object sender, EventArgs e)
      {
         OpenFileDialog fichero = new OpenFileDialog();
         if (fichero.ShowDialog() == DialogResult.OK)
         {
            try
            {
               StreamReader lector = new StreamReader(fichero.FileName);
               String linea;
               txtFichero.Text = String.Empty;
               while ((linea = lector.ReadLine()) != null)
               {
                  txtFichero.Text += linea + “rn”;
               }
               lector.Close();
            }
            catch (Exception ex)
            {
               MessageBox.Show(“Se ha producido algún error”);
            }
         }
      }
   }
}

Quizá te interese...

Deja un comentario...

Suscribirme
Notificación de
guest
0 Comentarios
Comentarios en línea
Ver todos los comentarios