H
hansiman
Coming from classic asp, I'm a bit in the dark here.
I want to dispaly the content of a file in a literal server control.
I've created a class utils.vb
Imports System.IO
Public Class Utils
Inherits System.Web.UI.Page
Public Function ReadFile(ByVal pFile) ' As String
Dim ForReading As Integer = 1
Dim fso As Object
Dim ts
Dim s
fso = CreateObject("Scripting.FileSystemObject")
ts = fso.OpenTextFile(MapPath(pFile), ForReading)
s = ts.ReadAll
ts.Close()
ReadFile = s
End Function
End Class
on the aspx page I use
Dim utl As Utils = New Utils
Dim lBody As String = utl.ReadFile( strFile )
litContent.Text = lBody
If I have the ReadFile function in the code behind page of the calling
aspx page it works.
When I move the function to the utils.vb class I get the following
error:
System.NullReferenceException: Object reference not set to an instance
of an object
Line 11: Dim s
Line 12: fso = CreateObject("Scripting.FileSystemObject")
Line 13: ts = fso.OpenTextFile(MapPath(pFile), ForReading)
Line 14: s = ts.ReadAll
Line 15: ts.Close()
Source File: c:\inetpub\wwwroot\project\Utils.vb Line: 13
I figure its the dim ts part of ReadFile function. But ...???
/Morten
I want to dispaly the content of a file in a literal server control.
I've created a class utils.vb
Imports System.IO
Public Class Utils
Inherits System.Web.UI.Page
Public Function ReadFile(ByVal pFile) ' As String
Dim ForReading As Integer = 1
Dim fso As Object
Dim ts
Dim s
fso = CreateObject("Scripting.FileSystemObject")
ts = fso.OpenTextFile(MapPath(pFile), ForReading)
s = ts.ReadAll
ts.Close()
ReadFile = s
End Function
End Class
on the aspx page I use
Dim utl As Utils = New Utils
Dim lBody As String = utl.ReadFile( strFile )
litContent.Text = lBody
If I have the ReadFile function in the code behind page of the calling
aspx page it works.
When I move the function to the utils.vb class I get the following
error:
System.NullReferenceException: Object reference not set to an instance
of an object
Line 11: Dim s
Line 12: fso = CreateObject("Scripting.FileSystemObject")
Line 13: ts = fso.OpenTextFile(MapPath(pFile), ForReading)
Line 14: s = ts.ReadAll
Line 15: ts.Close()
Source File: c:\inetpub\wwwroot\project\Utils.vb Line: 13
I figure its the dim ts part of ReadFile function. But ...???
/Morten