473,382 Members | 1,147 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,382 software developers and data experts.

server.mappath in a vb class

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 with context because
server.mappath does not work there.
I was thinking I'd just need to be more specific with the namespace and
tried HttpServerUtility.MapPath() (found this in help) but if I try to use
that directly, Intellisense won't accept it saying "Reference to a
non-shared member requires an object reference." so I declared a variable as
a HttpServerUtility, but that fails at runtime with a null object reference
error.

So all I really want to do is be able to refer to my application root folder
from a vb class in my asp.net application. Not sure if I'm close in my
approach above, but if someone could give me a hint on how to do this I'd
really appreciate it. I just want it to work like Server.MapPath in a
codebehind page. Thanks!

Matt
Nov 18 '05 #1
3 8650
Server and HttpServerUtility are equivalent overall. The best way to use it
is to create a HttpServerUtility object and pass it in to your class file.
Server is an instantiated copy of HttpServerUtility; you just do not see the
instantiation.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"MattB" <so********@yahoo.com> wrote in message
news:2p************@uni-berlin.de...
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 with context because
server.mappath does not work there.
I was thinking I'd just need to be more specific with the namespace and
tried HttpServerUtility.MapPath() (found this in help) but if I try to use
that directly, Intellisense won't accept it saying "Reference to a
non-shared member requires an object reference." so I declared a variable as a HttpServerUtility, but that fails at runtime with a null object reference error.

So all I really want to do is be able to refer to my application root folder from a vb class in my asp.net application. Not sure if I'm close in my
approach above, but if someone could give me a hint on how to do this I'd
really appreciate it. I just want it to work like Server.MapPath in a
codebehind page. Thanks!

Matt

Nov 18 '05 #2
Thanks for the response!
If possible I'd like to not have to pass it in. Is there anyway I can
instantiate it in my vb class so I don't need to modify code that calls this
class elsewhere?

Cowboy (Gregory A. Beamer) [MVP] wrote:
Server and HttpServerUtility are equivalent overall. The best way to
use it is to create a HttpServerUtility object and pass it in to your
class file. Server is an instantiated copy of HttpServerUtility; you
just do not see the instantiation.
************************************************
Think Outside the Box!
************************************************
"MattB" <so********@yahoo.com> wrote in message
news:2p************@uni-berlin.de...
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
with context because server.mappath does not work there.
I was thinking I'd just need to be more specific with the namespace
and tried HttpServerUtility.MapPath() (found this in help) but if I
try to use that directly, Intellisense won't accept it saying
"Reference to a non-shared member requires an object reference." so
I declared a variable as a HttpServerUtility, but that fails at
runtime with a null object reference error.

So all I really want to do is be able to refer to my application
root folder from a vb class in my asp.net application. Not sure if
I'm close in my approach above, but if someone could give me a hint
on how to do this I'd really appreciate it. I just want it to work
like Server.MapPath in a codebehind page. Thanks!

Matt


Nov 18 '05 #3
You don't need to instantiate it. You need to reference it. It already
exists in the HttpContext of the Current Request:

string s = System.Web.HttpContext.Current.Server.MapPath(url) ;

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"MattB" <so********@yahoo.com> wrote in message
news:2p************@uni-berlin.de...
Thanks for the response!
If possible I'd like to not have to pass it in. Is there anyway I can
instantiate it in my vb class so I don't need to modify code that calls this class elsewhere?

Cowboy (Gregory A. Beamer) [MVP] wrote:
Server and HttpServerUtility are equivalent overall. The best way to
use it is to create a HttpServerUtility object and pass it in to your
class file. Server is an instantiated copy of HttpServerUtility; you
just do not see the instantiation.
************************************************
Think Outside the Box!
************************************************
"MattB" <so********@yahoo.com> wrote in message
news:2p************@uni-berlin.de...
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
with context because server.mappath does not work there.
I was thinking I'd just need to be more specific with the namespace
and tried HttpServerUtility.MapPath() (found this in help) but if I
try to use that directly, Intellisense won't accept it saying
"Reference to a non-shared member requires an object reference." so
I declared a variable as a HttpServerUtility, but that fails at
runtime with a null object reference error.

So all I really want to do is be able to refer to my application
root folder from a vb class in my asp.net application. Not sure if
I'm close in my approach above, but if someone could give me a hint
on how to do this I'd really appreciate it. I just want it to work
like Server.MapPath in a codebehind page. Thanks!

Matt


Nov 18 '05 #4

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

Similar topics

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! ...
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...
1
by: Steve | last post by:
I have a class that I need to use Server.MapPath(), when I try to compile, I get this error: The type or namespace name 'Server' could not be found (are you missing a using directive or an...
6
by: Nathan Sokalski | last post by:
When using the Server.MapPath() method, the results being returned are given as locations on my hard drive. I would like to be returned a result that is a URL, in my case something like the...
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...
2
by: Scott | last post by:
Hi there, I am writing a webservice and am wanting to use Server.MapPath to get the path to some files on the server that is hosting the webservice. I am using VB.NET atm, but am learning C#, so...
2
by: WB | last post by:
Hi, How can I access Server and Trace within a helper class? I have a webform that allows user to select a PDF file (on the web server) and render a jpeg image of that PDF file. The helper...
3
by: Han | last post by:
Hello I have an website having a class to be used by my .aspx, .asmx in the same project. Also I have a common directory for XSL files. From .aspx I retrieve the files by server.mappath("~...")....
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.