473,802 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using Server.MapPath

Hi,

Can somebody tell me why can't I use
string strPath = Server.MapPath( Request.Applica tionPath);
in
protected void Application_Sta rt(...)

It compiles ok but an unhandled exception occurred during the execution.
Exception Details: System.NullRefe renceException: Object reference not set
to an instance of an object.

I have no problem using the above code in private void Page_Load(...)

Thanks,
Kian
Nov 17 '05 #1
3 7273
There is no Request yet when your application is starting up.
The Request object is not yet in scope.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Kian Goh" <ki************ @hotmail.com> wrote in message
news:eP******** ********@tk2msf tngp13.phx.gbl. ..
Hi,

Can somebody tell me why can't I use
string strPath = Server.MapPath( Request.Applica tionPath);
in
protected void Application_Sta rt(...)

It compiles ok but an unhandled exception occurred during the execution.
Exception Details: System.NullRefe renceException: Object reference not set
to an instance of an object.

I have no problem using the above code in private void Page_Load(...)

Thanks,
Kian

Nov 17 '05 #2
Thanks Steve.

I intended to implement a counter for my webpage. I store my counter value
in a text file located in the ApplicationPath . I will read the counter from
the file on application start up and increment the value on every new
session created. Counter will be written on to the file at the end of
application.

If there is no Request yet during the application start up, is there any way
for me to know the ApplicationPath . At the moment, I am using hard coded
path.

OR let me know if there is other way to implement a counter.

Thanks,
Kian

=============== =============== ======
INSIDE protected void Application_Sta rt(...)
=============== =============== ======
StreamReader sr = File.OpenText(" d:\\kk\\omac\\o macCounter.txt" );
Application["Counter"] =
System.Convert. ToInt16(sr.Read ToEnd().ToStrin g());
=============== =============== ======

"Steve C. Orr, MCSD" <St***@Orr.ne t> wrote in message
news:e2******** ******@TK2MSFTN GP09.phx.gbl...
There is no Request yet when your application is starting up.
The Request object is not yet in scope.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Kian Goh" <ki************ @hotmail.com> wrote in message
news:eP******** ********@tk2msf tngp13.phx.gbl. ..
Hi,

Can somebody tell me why can't I use
string strPath = Server.MapPath( Request.Applica tionPath);
in
protected void Application_Sta rt(...)

It compiles ok but an unhandled exception occurred during the execution.
Exception Details: System.NullRefe renceException: Object reference not set to an instance of an object.

I have no problem using the above code in private void Page_Load(...)

Thanks,
Kian


Nov 17 '05 #3
Well one solution would be to store the path in your web.config file.
Then in your code you can get the path like this:
Dim sMyPath As String = ConfigurationSe ttings.AppSetti ngs("AppPath")
Here's more info:
http://msdn.microsoft.com/library/de...tingstopic.asp

But a better solution might be to user the Server.Mappath method instead. I
believe the Server object is in scope in the Application_Sta rt procedure.
Here's more info:
http://msdn.microsoft.com/library/de...ppathtopic.asp

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Kian Goh" <ki************ @hotmail.com> wrote in message
news:OL******** *****@TK2MSFTNG P11.phx.gbl...
Thanks Steve.

I intended to implement a counter for my webpage. I store my counter value
in a text file located in the ApplicationPath . I will read the counter from the file on application start up and increment the value on every new
session created. Counter will be written on to the file at the end of
application.

If there is no Request yet during the application start up, is there any way for me to know the ApplicationPath . At the moment, I am using hard coded
path.

OR let me know if there is other way to implement a counter.

Thanks,
Kian

=============== =============== ======
INSIDE protected void Application_Sta rt(...)
=============== =============== ======
StreamReader sr = File.OpenText(" d:\\kk\\omac\\o macCounter.txt" );
Application["Counter"] =
System.Convert. ToInt16(sr.Read ToEnd().ToStrin g());
=============== =============== ======

"Steve C. Orr, MCSD" <St***@Orr.ne t> wrote in message
news:e2******** ******@TK2MSFTN GP09.phx.gbl...
There is no Request yet when your application is starting up.
The Request object is not yet in scope.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Kian Goh" <ki************ @hotmail.com> wrote in message
news:eP******** ********@tk2msf tngp13.phx.gbl. ..
Hi,

Can somebody tell me why can't I use
string strPath = Server.MapPath( Request.Applica tionPath);
in
protected void Application_Sta rt(...)

It compiles ok but an unhandled exception occurred during the execution. Exception Details: System.NullRefe renceException: Object reference not set to an instance of an object.

I have no problem using the above code in private void Page_Load(...)

Thanks,
Kian



Nov 17 '05 #4

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

Similar topics

13
14331
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a path within c:\Inetpub\wwwroot rather than the real path. Can anyone please tell me why this isn't working? Regards, John
0
3409
by: canasdaq | last post by:
Can anyone please help me. I was looking at the article "http://www.eggheadcafe.com/articles/20030603.asp". I am new to .net and know nothing in c#. I want to write a menu in asp.net. Can anyone please help me in converting this c# code to vb.net. I tried, but it is not giving the output. Here is the c# code using System using System.Collections using System.ComponentModel using System.Data using System.Drawing using System.Web using...
1
1349
by: Stephen | last post by:
I have the following for a datagrid that inserts a row into an xml file. It works great, but inserts the data to a new top-level node. I don't know how to specifiy an existing node for the inserted item: void DataGrid1_Update(Object Sender, DataGridCommandEventArgs e) { try { string stitle = (e.Item.Cells.FindControl("txttitle") as TextBox).Text; DataSet ds = new DataSet();
2
23955
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 either example will be fine. I have searched all over the newsgroups and forums to get an example and have found many, but am unable to get any working. I have got the webservice working, without the call to MapPath. But when I try a simple...
4
7195
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
15071
by: rn5a | last post by:
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path. Assuming that a file named Hello.aspx resides in C:\Inetpub\wwwroot\MyFolder, the output of both Response.Write(Server.MapPath("Hello.aspx")) & Response.Write(Request.MapPath("Hello.aspx"))
6
7948
by: withers | last post by:
If I run Server.MapPath("/") on my operational Internet server I get, correctly, the physical path to the directory my page is in (d:\.... \...\htdocs). If I run Server.MapPath("/") on my intranet server, my localhost, I get c:\inetpub\wwwroot, but my webpages are NOT in this folder, they are in c:\webtest. How to I establish the correct physical root on my intranet server?
7
3210
by: jain2005k | last post by:
How can I rename a .jpg file in server using asp( not asp.net) code I use the FileSystemObject to do that like Fso = Server.CreateObject("Scripting.FileSystemObject"); Fso.MoveFile(Server.MapPath("1.jpg"),(Server.MapPath("2.jpg")); but it does not work properly when I use the the code in my local system it also not worked. But when I put full filepathpath instead of mapPath in my local system. Like
3
4136
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have one line code in my program, occasionaly I will receive the following error: "The Path parameter for the MapPath method did not correspond to a known path" Path=Server.MapPath(sCertPath & "\" & order_id & ".pdf") I am wondering what is happening since every time I check my error log, the
0
9699
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.