ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

SaveToFile

This Extension Method saves string content to a file

Source

Imports System.Runtime.CompilerServices

Module m_Extensions
<Extension()> Public Function SaveToFile(ByVal Expression As String, ByVal Filename As String) As Exception
        Try
            Dim SW As New System.IO.StreamWriter(Filename, False, System.Text.Encoding.Default)
            SW.Write(Expression)
            SW.Flush()
            SW.Close()
            Return Nothing
        Catch ex As Exception
            Return ex
        End Try
    End Function
End Module

Example

Dim Text as string = "Example for 'SaveToFile' Extension"

Dim E As Exception = Text.SaveToFile("c:\data.txt")
If E IsNot Nothing Then
   MessageBox.Show(E.ToString)
End If

Author: Massimo Da Frassini

Submitted on: 1 dec 2009

Language: VB

Type: System.String

Views: 4050