473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Server.MapPath Failing When Moved to Class Module

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.
Nov 17 '05 #1
2 3274
"Jeff S" <Je***@asdf.net> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
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"
--
[[((hillarie))]]

To reply by email, remove ".SPAMBLOCK" from email address

Nov 17 '05 #2
Try it in this format:
MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("/") & "../data/myDB.mdb;"

David Wier
MCP, MVP ASP.NET, ASPInsider
http://aspnet101.com
http://aspexpress.com
"Jeff S" <Je***@asdf.net> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig | last post by:
In my code I have this line of code.... CrystalReportViewer1.ReportSource = Server.MapPath("CrystalReportSummary.rpt") I moved the file, CrystalReportSummary.rpt, and I get an error. The...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
3
by: MattB | last post by:
Server.MapPath works fine for me in a CodeBehind file, but when I try and move that code to a vb class it doesn't. What do I need to change to make Server.MapPath work from my vb class? Thanks! ...
2
by: Tee | last post by:
Hi, I am currently using Server.MapPath in my aspx files, but because of I am using it more than once, I would like to move these code away from aspx and make it as a public function inside...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
3
by: MattB | last post by:
If I use server.mappath to get to the root dir of my application from within codebehind, it works fine. I also want to use this from a vb class I have in my application, and I think I have an issue...
0
by: awbacker | last post by:
Havin a problem with MapPath() failing on me. It doesn't do it right away, but at some point it dies and won't come back. I have to hiccup the app by poking IIS or a web.config/other critical...
6
by: darrel | last post by:
I have some functions that are reading/writing to the file system. As such, they use server.mapPath a lot to navigate it all. Since I'm using these functions numerous times throughout my...
7
by: Electric Co. | last post by:
Hello, note: This is for a Faculty web site that is undergoing a migration to an open source solution so my motives are legit. I need to build a relay from IIS handling URL_A to a PHP server...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.