Server.MapPath Failing When Moved to Class Module

  • Thread starter Thread starter Jeff S
  • Start date Start date
J

Jeff S

In a VB/ASP.NET project, the following lines work as advertised when placed
in a code-behind file (whatever.aspx.vb) - meaning that I get the full
physical path to MyDatabase.MDB in the variable PathToMDB. However, when the
same two lines are moved to a separate class file (whatever.vb), the project
fails to build - with the message "Name 'Server' is not declared."

Dim PathToMDB As String
PathToMDB = Server.MapPath("/MySite/db/") + "MyDatabase.mdb"


Why is this? What can I do about it? I need to obtain the physical path to
the MDB file from within the class file.

Thanks in advance.
 
Jeff S said:
In a VB/ASP.NET project, the following lines work as advertised when placed
in a code-behind file (whatever.aspx.vb) - meaning that I get the full
physical path to MyDatabase.MDB in the variable PathToMDB. However, when the
same two lines are moved to a separate class file (whatever.vb), the project
fails to build - with the message "Name 'Server' is not declared."

Dim PathToMDB As String
PathToMDB = Server.MapPath("/MySite/db/") + "MyDatabase.mdb"


Why is this? What can I do about it? I need to obtain the physical path to
the MDB file from within the class file.

Thanks in advance.


Try
HttpContext.Current.Server.MapPath("/MySite/db/") + "MyDatabase.mdb"
 
Back
Top