archivo

14/11/2004 - 21:55 por luis | Informe spam
hola!!

quisiera saber el codigo para modificar un archivo,
ponerlo en un txtbox y guardarlo, sin un opensavedialog ,

Preguntas similare

Leer las respuestas

#1 Octavio Hernandez
14/11/2004 - 22:20 | Informe spam
Si utilizas un control RichTextBox lo tendrás muy fácil:

RichTextBox1.LoadFile("C:\\Ejemplo.txt",
RichTextBoxStreamType.PlainText);

y

RichTextBox1.SaveFile("C:\\Ejemplo.txt",
RichTextBoxStreamType.PlainText);

Salu2,

Octavio

"luis" escribió en el mensaje
news:57f901c4ca8c$51f0e330$
hola!!

quisiera saber el codigo para modificar un archivo,
ponerlo en un txtbox y guardarlo, sin un opensavedialog ,

Respuesta Responder a este mensaje
#2 Richard Blas Palacios
15/11/2004 - 05:02 | Informe spam
Hola Luis, Podrías usar lo siguiente:

using system.IO;
using System.Text;

private void btnLeer_Click(object sender, System.EventArgs e)
{
string pathFile;
System.IO.Stream oArchivo;

pathFile = "D:/Pruebas/MiTexto.txt";

if (File.Exists(pathFile))
{
//Abrir y Leer
oArchivo = File.Open(pathFile, FileMode.Open,
FileAccess.ReadWrite, FileShare.None);
byte[] str = new byte[1024];
UTF8Encoding txt = new UTF8Encoding(true);

while(oArchivo.Read(str, 0, str.Length) > 0)
{
//Escribir Contenido en la Caja de Texto
this.txtTexto.Text = txt.GetString (str);
}

oArchivo.Close();
}
else
MessageBox.Show("El Archivo Solicitado no existe", "Mensaje",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void btnGuardar_Click(object sender, System.EventArgs e)
{
string pathFile;
System.IO.Stream oArchivo;

pathFile = "D:/Pruebas/MiTexto.txt";

//En caso no exista el archivo lo crea
if (!System.IO.File.Exists(pathFile))
oArchivo = File.Create(pathFile);
else
{
//En caso exista abre el archivo y lee
oArchivo = File.Open(pathFile, FileMode.Open,
FileAccess.ReadWrite, FileShare.Write);
}


//Escribir y Guardar en el File
byte[] str = new UTF8Encoding(true).GetBytes(this.txtTexto.Text);
oArchivo.Write(str, 0, str.Length);
oArchivo.Close();
}

Espero te sirva, Saludos.

J. Richard Blas Palacios
Analista Desarrollador - Gesfor Osmos Perú





"luis" wrote in message
news:57f901c4ca8c$51f0e330$
hola!!

quisiera saber el codigo para modificar un archivo,
ponerlo en un txtbox y guardarlo, sin un opensavedialog ,

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida