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!

No comments:

Post a Comment