Ask a Question related to ASP.NET General, Design and Development.
-
Kian Goh #1
using Server.MapPath
Hi,
Can somebody tell me why can't I use
string strPath = Server.MapPath(Request.ApplicationPath);
in
protected void Application_Start(...)
It compiles ok but an unhandled exception occurred during the execution.
Exception Details: System.NullReferenceException: 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
Kian Goh Guest
-
this.Context.Server.MapPath
can get the Server.MapPath to work in run-mode, but not in the property desinger window. It will throw an error. Try to read a xml file in the... -
Accessing Server.Mappath from SoapExtension
I need to log all incoming soap messages in a file. I have follwing code in WriteInput routine of SoapExtension class Dim Server As... -
Server.MapPath connection string question.
I have two sites: www.site_A.com & www.site_A_news.com Site_A is in d:\webs\site_a & uses an Access DB in d:\webs\site_a\data\db.mdb ... -
Server.MapPath returning wrong path
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... -
Server MapPath
Hello folks. How do I solve the problem below? when my program executes the line below : Package.WriteXml(Server.MapPath(strID + ".XML")); ... -
Steve C. Orr, MCSD #2
Re: using Server.MapPath
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
[url]http://Steve.Orr.net[/url]
"Kian Goh" <kiangoh2700544@hotmail.com> wrote in message
news:ePw%23YfiUDHA.3916@tk2msftngp13.phx.gbl...> Hi,
>
> Can somebody tell me why can't I use
> string strPath = Server.MapPath(Request.ApplicationPath);
> in
> protected void Application_Start(...)
>
> It compiles ok but an unhandled exception occurred during the execution.
> Exception Details: System.NullReferenceException: 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
>
>
Steve C. Orr, MCSD Guest
-
Kian Goh #3
Re: using Server.MapPath
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_Start(...)
====================================
StreamReader sr = File.OpenText("d:\\kk\\omac\\omacCounter.txt");
Application["Counter"] =
System.Convert.ToInt16(sr.ReadToEnd().ToString());
====================================
"Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
news:e2dVAoiUDHA.2316@TK2MSFTNGP09.phx.gbl...set> 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
> [url]http://Steve.Orr.net[/url]
>
>
>
> "Kian Goh" <kiangoh2700544@hotmail.com> wrote in message
> news:ePw%23YfiUDHA.3916@tk2msftngp13.phx.gbl...> > Hi,
> >
> > Can somebody tell me why can't I use
> > string strPath = Server.MapPath(Request.ApplicationPath);
> > in
> > protected void Application_Start(...)
> >
> > It compiles ok but an unhandled exception occurred during the execution.
> > Exception Details: System.NullReferenceException: Object reference not>> > to an instance of an object.
> >
> > I have no problem using the above code in private void Page_Load(...)
> >
> > Thanks,
> > Kian
> >
> >
>
Kian Goh Guest
-
Steve C. Orr, MCSD #4
Re: using Server.MapPath
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 = ConfigurationSettings.AppSettings("AppPath")
Here's more info:
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconfigurationconfigurationsettingsclass appsettingstopic.asp[/url]
But a better solution might be to user the Server.Mappath method instead. I
believe the Server object is in scope in the Application_Start procedure.
Here's more info:
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttpserverutilityclassmappathtopic.a sp[/url]
--
I hope this helps,
Steve C. Orr, MCSD
[url]http://Steve.Orr.net[/url]
"Kian Goh" <kiangoh2700544@hotmail.com> wrote in message
news:OLlwcziUDHA.360@TK2MSFTNGP11.phx.gbl...from> 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 counterway> 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 anyexecution.> 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_Start(...)
> ====================================
> StreamReader sr = File.OpenText("d:\\kk\\omac\\omacCounter.txt");
> Application["Counter"] =
> System.Convert.ToInt16(sr.ReadToEnd().ToString());
> ====================================
>
>
>
> "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
> news:e2dVAoiUDHA.2316@TK2MSFTNGP09.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
> > [url]http://Steve.Orr.net[/url]
> >
> >
> >
> > "Kian Goh" <kiangoh2700544@hotmail.com> wrote in message
> > news:ePw%23YfiUDHA.3916@tk2msftngp13.phx.gbl...> > > Hi,
> > >
> > > Can somebody tell me why can't I use
> > > string strPath = Server.MapPath(Request.ApplicationPath);
> > > in
> > > protected void Application_Start(...)
> > >
> > > It compiles ok but an unhandled exception occurred during the> set> > > Exception Details: System.NullReferenceException: Object reference not>> >> > > to an instance of an object.
> > >
> > > I have no problem using the above code in private void Page_Load(...)
> > >
> > > Thanks,
> > > Kian
> > >
> > >
> >
>
Steve C. Orr, MCSD Guest
-
John #5
Using server.mappath
Hi
On my local server the physical db path is
"C:/Inetpub/wwwroot/StaffDiary/Cal.mdb". I am using the virtual path as
conn.Open Server.MapPath("Cal.mdb") but I am getting a;
Microsoft JET Database Engine (0x80004005)
Unspecified error
error. What am I doing wrong?
Thanks
Regards
John Guest
-
Bullschmidt #6
Re: Using server.mappath
Able Consulting - ADO Connection String Samples
[url]http://www.able-consulting.com/ADO_Conn.htm[/url]
Best regards,
J. Paul Schmidt, Freelance ASP Web Designer
[url]http://www.Bullschmidt.com[/url]
ASP Designer Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Devdex [url]http://www.devdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Bullschmidt Guest
-
Aaron [SQL Server MVP] #7
Re: Using server.mappath
[url]http://www.aspfaq.com/2126[/url]
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
"John" <john@nospam.infovis.co.uk> wrote in message
news:Oa6s$r9VEHA.3472@TK2MSFTNGP09.phx.gbl...> Hi
>
> On my local server the physical db path is
> "C:/Inetpub/wwwroot/StaffDiary/Cal.mdb". I am using the virtual path as
> conn.Open Server.MapPath("Cal.mdb") but I am getting a;
>
> Microsoft JET Database Engine (0x80004005)
> Unspecified error
>
> error. What am I doing wrong?
>
> Thanks
>
> Regards
>
>
Aaron [SQL Server MVP] Guest



Reply With Quote

