Mostrando las entradas con la etiqueta StreamWriter. Mostrar todas las entradas
Mostrando las entradas con la etiqueta StreamWriter. Mostrar todas las entradas

martes, 31 de octubre de 2017

Escribir en un archivo txt

Dim wr As New StreamWriter("clientes.txt", True, System.Text.Encoding.UTF8)
wr.Close()

True ---> adjuntar-agrega líneas
False--->crea un archivo nuevo y agrega una línea

jueves, 3 de agosto de 2017

Insertar registro al inicio archivo txt

Public i As Integer = 0
Private Sub btnaceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaceptar.Click
        Dim filename As String = Directory.GetCurrentDirectory & "\log.txt"
        Dim tempfile As String = Path.GetTempFileName()
        i += 1
        Using writer = New StreamWriter(tempfile)
            Using reader = New StreamReader(filename)
                writer.WriteLine(Now.ToString("dd-MM-yyyy HH:mm:ss:ffff") & "|" & tbinsertar.Text.Trim & "|" & i)
                While Not reader.EndOfStream
                    writer.WriteLine(reader.ReadLine())
                End While
            End Using
        End Using
        File.Copy(tempfile, filename, True)
        File.Delete(tempfile)
    End Sub

fuente: https://stackoverflow.com/questions/2401523/how-to-insert-row-in-first-line-of-text-file

viernes, 28 de abril de 2017

Crear archivo txt


Dim archivo As String = "archivo.txt" 
If Not File.Exists(archivo) Then
            Dim sr As New StreamWriter(archivo)
            sr.Close()
            sr.Dispose()
        End If


viernes, 25 de noviembre de 2016

Crear un archivo log


Dim log As StreamWriter = Nothing
' log = Nothing
Try
log = New StreamWriter("log.txt", False, System.Text.Encoding.UTF8)
registro(log)
Catch ex As Exception
End Try

' Pasar a una función

Public Function registro(ByVal log As StreamWriter) As String
log.WriteLine("texto")
End Function