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 application, I
thought I'd move these into their own .vb class file and reference them that
way.
The catch is when moving these scripts over, 'Server.MapPath' turns into an
error "Name 'server' is not declared"
I'm assuming I need to expand Server.MapPath to show Server's parent class.
Alas, I have no idea what that is and google isn't helping much.
-Darrel 6 1582
From within a class, try using
System.Web.HttpServerUtility.MapPath http://beta.asp.net/QUICKSTART/util/...pServerUtility
Juan T. Llibre
ASP.NET MVP http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
"darrel" <no*****@hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP15.phx.gbl... 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 application, I thought I'd move these into their own .vb class file and reference them that way.
The catch is when moving these scripts over, 'Server.MapPath' turns into an error "Name 'server' is not declared"
I'm assuming I need to expand Server.MapPath to show Server's parent class. Alas, I have no idea what that is and google isn't helping much.
-Darrel
From what I can tell this will not help the OP as the MapPath method is not
static
To reply to the original question. Server is an instance member of the Page
class (well, it's in several places but I assume page is where you're
normally getting it from) and is, as Juan pointed out, of type
HttpServerUtility.
If you want to call Server.MapPath from a utility function, you have 2
choices:
1. pass in the Server object from the page to the utility function.
2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery
(well, thread local storage) this can dig out the server object associated
with the current request. N.B. If you call this function from a thread that
is not processing an HTTP request, it will barf at runtime.
HTH
Andy
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl... From within a class, try using
System.Web.HttpServerUtility.MapPath
http://beta.asp.net/QUICKSTART/util/...pServerUtility
Juan T. Llibre ASP.NET MVP http://asp.net.do/foros/ Foros de ASP.NET en Español Ven, y hablemos de ASP.NET... ======================
"darrel" <no*****@hotmail.com> wrote in message news:ev**************@TK2MSFTNGP15.phx.gbl...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 application, I thought I'd move these into their own .vb class file and reference them that way.
The catch is when moving these scripts over, 'Server.MapPath' turns into an error "Name 'server' is not declared"
I'm assuming I need to expand Server.MapPath to show Server's parent class. Alas, I have no idea what that is and google isn't helping much.
-Darrel
> From what I can tell this will not help the OP as the MapPath method is
not static
I'm not quite sure what you mean by that.
Specifically, I'm taking a virtual path:
/documents/shared/ and mapping it to the actual server, be it my local one
when testing or the live server when deploying.
To reply to the original question. Server is an instance member of the
Page class
Ah! Well, that explains it.
2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery (well, thread local storage) this can dig out the server object associated with the current request. N.B. If you call this function from a thread
that is not processing an HTTP request, it will barf at runtime.
This may be a naive question, but aren't all ASP.net threads part of a HTTP
request (ie, postbacks?)
-Darrel
> From what I can tell this will not help the OP as the MapPath method is not static
I wasn't looking too closely.
Thanks !
Juan T. Llibre
ASP.NET MVP http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... From what I can tell this will not help the OP as the MapPath method is not static
To reply to the original question. Server is an instance member of the Page class (well, it's in several places but I assume page is where you're normally getting it from) and is, as Juan pointed out, of type HttpServerUtility.
If you want to call Server.MapPath from a utility function, you have 2 choices:
1. pass in the Server object from the page to the utility function.
2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery (well, thread local storage) this can dig out the server object associated with the current request. N.B. If you call this function from a thread that is not processing an HTTP request, it will barf at runtime.
HTH
Andy
"Juan T. Llibre" <no***********@nowhere.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... From within a class, try using
System.Web.HttpServerUtility.MapPath
http://beta.asp.net/QUICKSTART/util/...pServerUtility
Juan T. Llibre ASP.NET MVP http://asp.net.do/foros/ Foros de ASP.NET en Español Ven, y hablemos de ASP.NET... ======================
"darrel" <no*****@hotmail.com> wrote in message news:ev**************@TK2MSFTNGP15.phx.gbl...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 application, I thought I'd move these into their own .vb class file and reference them that way.
The catch is when moving these scripts over, 'Server.MapPath' turns into an error "Name 'server' is not declared"
I'm assuming I need to expand Server.MapPath to show Server's parent class. Alas, I have no idea what that is and google isn't helping much.
-Darrel
"darrel" <no*****@hotmail.com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl... From what I can tell this will not help the OP as the MapPath method is not static
I'm not quite sure what you mean by that.
a static method of a class is one which you can invoke independently of
having an instance of that class - it's more like a global function. read up
on OO concepts if you're not clear on this. Specifically, I'm taking a virtual path:
/documents/shared/ and mapping it to the actual server, be it my local one when testing or the live server when deploying.
so either of my proposed solutions should work for you To reply to the original question. Server is an instance member of the Page class
Ah! Well, that explains it.
2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery (well, thread local storage) this can dig out the server object associated with the current request. N.B. If you call this function from a thread that is not processing an HTTP request, it will barf at runtime.
This may be a naive question, but aren't all ASP.net threads part of a HTTP request (ie, postbacks?)
yes (assuming the thread was created by asp.net to handle a request). I was
just making the point that if, for whatever reason, you call that function
from another thread (one you have started yourself or when including this
same utility function in a different application) it won't work -Darrel
> yes (assuming the thread was created by asp.net to handle a request). I
was just making the point that if, for whatever reason, you call that function from another thread (one you have started yourself or when including this same utility function in a different application) it won't work
Thanks, Andy. I appreciate the explanations!
-Darrel This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul J. Landry |
last post by:
HI Guys.
I hope you can help me out!
I'm writting a small app for my Intranet that allows me to see basic
information aount user accounts. Included in that information is disk quota
data...
|
by: Steven T. Hatton |
last post by:
This is something I've been looking at because it is central to a currently
broken part of the KDevelop new application wizard. I'm not complaining
about it being broken, It's a CVS images. ...
|
by: Bryan |
last post by:
We created a Windows Service with C#. The service will start OK on
computers that are a member of a domain, but when we try to start it on a
server that is configured for a workgroup we get the...
|
by: Steve Wark |
last post by:
I have a Windows 2003 Web server on which I was debugging remotely with no
problems.
I then moved this server to a different domain and now remote debugging will
not work, the error is;
...
|
by: Eidolon |
last post by:
We have a Win2K3 Web Edition server. I have the remote components installed
and am trying to attach to debug, but i cant find what process to attach to.
On Win2K its aspnet_wp.exe. That process...
|
by: Mike |
last post by:
Hi,
I am strugling with a simple problem which I can't seem to resolve.
I have an asp.net page which contains a server-control (flytreeview,
which is a kind
of a tree to be exact).
The tree is...
|
by: SlashDrew |
last post by:
I have created a custom control that has some design time support. I
can create a menubar with the following HTML
<Menu:BarMenu runat="server" id="MenuBar">
<MainMenuItems>
<Menu:BarMenuItem...
|
by: =?Utf-8?B?am9uZWZlcg==?= |
last post by:
I keep getting the message after I converted a regular aspx page to now be
based on a master page:
"Only Content controls are allowed directly in a content page that contains
Content controls."...
|
by: ringoschplingo |
last post by:
Hi, (sorry this is a long one)
I have MSSQL 2000 (version 8.00.2187) installed on Windows Server 2K3, nothing 'special' has been done to either of these servers as far as configuration goes.
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |