Friday, 4 June 2010

ASP.NET: Read Contents of Text File

In my Web Application Project, I wanted to read some CSS styles in from a file to dynamically style a system generated email.

It was pretty easy, but I thought I should record my code for future:

Dim emailCss As String = vbNullString

Dim fileName As String = HttpContext.Current.Server.MapPath("~/utilities/Email.css")

If File.Exists(fileName) Then
Dim ioFile As New StreamReader(fileName)

emailCss = ioFile.ReadToEnd()


End If