Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/04/2013, 05:14
Avatar de difilippocarlos
difilippocarlos
 
Fecha de Ingreso: junio-2010
Mensajes: 109
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: Exportar Multiples Consultas

Tenes el Try... dejanos el msj q te da el Catch...


te dejo una forma sencilla de escritura y lectura

Escritura Simple
Código:
 ' Crea el archivo  (Apodo, ruta/nombre, modo de apertura)
 FileOpen(1, "C:\Texto.txt", OpenMode.Output)
 ' escribe el contenido  (apodo, string)
 Write(1, TextBox1.Text)
' lo cierra
 FileClose(1)
La que uso yo
Código:
'Creamos un objeto de la clase StreamWriter(ruta\nombre.txt)
Dim objSW As New System.IO.StreamWriter("C:\archivo_prueba.txt")

'Declaramos el texto a colocar en el Archivo
Dim strArchivo As String = "Línea de texto " & vbNewLine & "Otra linea de texto"
'tambien lo podes hacer en un while
'con strArchivo = "Linea de Texto" & vbNewLine

'Ahora escribimos el archivo
objSW.WriteLine(strArchivo)
'y "cerramos" por asi decirlo
objSW.Flush()

Ahora la manera en la q yo leo 1 arhivo
Código:
Dim VarArchivo as string
 Try
        Dim sPath As String = "c:\un_archivo.txt"
        Dim sContent As String = vbNullString

        With My.Computer.FileSystem
             ' verifica si existe el path  
             If .FileExists(SPath) Then
                  ' lee todo el contenido  
                  sContent = .ReadAllText(SPath)
                 VarArchivo = sContent.ToString
             Else
                  MsgBox("ruta inválida", MsgBoxStyle.Critical, "error")
             End If
        End With
        ' errores  
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
        End Try