Write To A File on Server in ASP.NET

    Public Shared Function SaveTextToFile(ByVal strData As String, ByVal fname As String) As Boolean
        Try
            Dim fs As New FileStream(fname, FileMode.Create, FileAccess.Write)
            Dim s As New StreamWriter(fs)
            s.BaseStream.Seek(0, SeekOrigin.End)
            s.WriteLine(strData)
            s.Close()
            Return True
        Catch ex As Exception
            ' your exception handler here
        End Try
        Return False
    End Function

2 comments: