Foros del Web » Programando para Internet » ASPX (.net) »

leer .txt

Estas en el tema de leer .txt en el foro de ASPX (.net) en Foros del Web. Hola muy buenas, me he frustado al saber que vb.net no tiene el include() como el de php, buno como no quiero inlucir ningun .aspx ...
  #1 (permalink)  
Antiguo 21/07/2010, 10:12
Avatar de angel1993  
Fecha de Ingreso: octubre-2009
Mensajes: 752
Antigüedad: 14 años, 6 meses
Puntos: 22
leer .txt

Hola muy buenas, me he frustado al saber que vb.net no tiene el include() como el de php, buno como no quiero inlucir ningun .aspx solo necesito incluir un .txt
la solucion seria leer el texto, buscando he encontrado esto
Código ASP:
Ver original
  1. FileOpen(1, "hola.txt", OpenMode.Input)
  2.         While (EOF(1) = False)
  3.             Response.Write(LineInput(1))
  4.        
  5.  
  6.         End While
  7.         FileClose(1)
y bueno el web.config dice que eso esta escrito en C#
necesito leerlo desde vb :)
Gracias por adelantado
  #2 (permalink)  
Antiguo 21/07/2010, 15:01
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: leer .txt

Sería algo así:

Código ASP:
Ver original
  1. Sub WriteToFile(sender As Object, e As EventArgs)
  2.  
  3.         Dim fp As StreamReader
  4.  
  5.         Try
  6.             fp = File.OpenText(Server.MapPath(".\Upload\") & "test.txt")
  7.             txtMyFile.Text = fp.ReadToEnd()
  8.             lblStatus.Text = "File Succesfully Read!"
  9.             fp.Close()
  10.         Catch err As Exception
  11.             lblStatus.Text = "File Read Failed. Reason is as follows
  12.  
  13. " & err.ToString()
  14.         Finally
  15.  
  16.         End Try
  17.  
  18.     End Sub

O bien

Código ASP:
Ver original
  1. Dim StreamReader1 As New System.IO.StreamReader(Server.MapPath("test.txt"))
  2. TextBox2.Text = StreamReader1.ReadToEnd()
  3. StreamReader1.Close()
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!

Etiquetas: txt, aspx
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:39.