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

LoadFromFile

Read and assign a file content to String Variable

Source

Module m_Extensions
<Extension()> Public Function LoadFromFile(ByVal Expression As String, ByVal Filename As String) As Exception
        Try
            Dim oRead As New System.IO.StreamReader(Filename, System.Text.Encoding.Default)
            Expression = oRead.ReadToEnd
            oRead.Close()
            Return Nothing
        Catch ex As Exception
            Return ex
        End Try
    End Function
End Module

Example

Dim Text As String
Dim E As Exception = Text.LoadFromFile("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: 5985