Showing posts with label File. Show all posts
Showing posts with label File. Show all posts

Sunday, February 7, 2010

Replace any Character in Text File in Vb.net

Sub Main()
Dim Fs As FileStream = New FileStream("c:\Edit1.TXT",FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim sw As New StreamWriter(Fs)
Dim sr As New StreamReader(Fs)
Dim str As String
str = sr.ReadToEnd()
str = str.Replace(vbCrLf, "^")
Fs.Position = 0
Fs.SetLength(str.Length)
sw.Write(str)
sw.Flush()
sw.Close()
Fs.Close()
End Sub

Happy Coding!

Tuesday, November 3, 2009

To Read Line By Line of Text File in VB.net 2.0

In this Post I have shown the simple code snippet for reading a text file line by line.

Dim strFileName As String = String.Empty
Dim fs As FileStream = Nothing
Dim m_streamReader As StreamReader = Nothing
Dim strCompany As String = String.Empty

fs = New FileStream(strFilePath, FileMode.Open, FileAccess.Read)
m_streamReader = New StreamReader(fs)
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin)

Do
strContent = m_streamReader.ReadLine()

Loop While (Not m_streamReader.EndOfStream)

Sunday, September 27, 2009

To Write and Save a Text File in Asp.Net 2.0

In this post I will show u the simple code snippet to write and save a text file in specific folder in asp.net using vb code


Public Sub WriteTextandSaveFile()

Dim fs As FileStream = Nothing
Dim sw As StreamWriter = Nothing

Try
fs = New FileStream("D:\Sample\Sample1.txt", FileMode.Create, FileAccess.Write)
sw = New StreamWriter(fs)
sw.WriteLine("This is Sample text")

Catch ex As Exception

Finally
sw.Close()
fs.Close()
sw.Dispose()
fs.Dispose()
End Try


End Sub


never regret anything, if it was good, its wonderful, if it was bad, its experience!