p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspx thread: Request.PhysicalApplicationPath not working in my aspx page?


Message #1 by chadm@d... on Thu, 4 Jul 2002 17:45:21
I've seen the code Request.PhysicalApplicationPath in "Professional 
ASP.NET 1.0" but when I try to use it I get an error:

CS0120: An object reference is required for the nonstatic field, method, 
or property 'System.Web.UI.Page.Request'

I thought the aspx page was the object and Request.whatever would run. I 
have seen this type of reference before. Why doesn't it work for me?

my code:
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-
1" %>
<script language="C#" runat="server">
string path = Request.PhysicalApplicationPath;
</script>

<html>
<head>
<title>Return the path</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%= path %>
</body>
</html>

Message #2 by "Dave Rezoski" <daverezoski@h...> on Thu, 04 Jul 2002 17:02:54 +0000
this works for me (in the codebehind, in page_load ... C#)

sAppPath = (this.Request.ServerVariables.Get("APPL_PHYSICAL_PATH"));


----Original Message Follows----
From: chadm@d...
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Request.PhysicalApplicationPath not working in my aspx page?
Date: Thu, 4 Jul 2002 17:45:21

I've seen the code Request.PhysicalApplicationPath in "Professional
ASP.NET 1.0" but when I try to use it I get an error:

CS0120: An object reference is required for the nonstatic field, method,
or property 'System.Web.UI.Page.Request'

I thought the aspx page was the object and Request.whatever would run. I
have seen this type of reference before. Why doesn't it work for me?

my code:
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-
1" %>
<script language="C#" runat="server">
string path = Request.PhysicalApplicationPath;
</script>

<html>
<head>
<title>Return the path</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%= path %>
</body>
</html>





_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Message #3 by "Chadrick" <chadm@d...> on Thu, 4 Jul 2002 13:10:09 -0400
Thanks Dave - I found another way to do it too if anyone is interested.

string path = HttpContext.Current.Request.PhysicalApplicationPath;

-----Original Message-----
From: Dave Rezoski [mailto:daverezoski@h...] 
Sent: Thursday, July 04, 2002 1:03 PM
To: ASP+
Subject: [aspx] Re: Request.PhysicalApplicationPath not working in my
aspx page?

this works for me (in the codebehind, in page_load ... C#)

sAppPath = (this.Request.ServerVariables.Get("APPL_PHYSICAL_PATH"));


----Original Message Follows----
From: chadm@d...
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Request.PhysicalApplicationPath not working in my aspx
page?
Date: Thu, 4 Jul 2002 17:45:21

I've seen the code Request.PhysicalApplicationPath in "Professional
ASP.NET 1.0" but when I try to use it I get an error:

CS0120: An object reference is required for the nonstatic field, method,
or property 'System.Web.UI.Page.Request'

I thought the aspx page was the object and Request.whatever would run. I
have seen this type of reference before. Why doesn't it work for me?

my code:
<%@ Page Language="C#" ContentType="text/html"
ResponseEncoding="iso-8859-
1" %>
<script language="C#" runat="server">
string path = Request.PhysicalApplicationPath;
</script>

<html>
<head>
<title>Return the path</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%= path %>
</body>
</html>





_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com





Message #4 by "Subraya Hegde" <subrayah@i...> on Fri, 5 Jul 2002 08:43:38 +0530
Better you write the code in this way, this will work....

<%@ Page Language="C#" %>
<script language="C#" runat="server">
 string path;
  void Page_Load(Object sender, EventArgs e) {              
       path = Request.PhysicalApplicationPath;
  }  
</script>
<html>
<head>
<title>Return the path</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
  <form runat="server">  
     <%=path%>
  </form>
</body>
</html>

Best Of Luck,
-HegdeS
Message #5 by "Mingkun Goh" <mangokun@h...> on Sat, 6 Jul 2002 15:10:16
> I've seen the code Request.PhysicalApplicationPath in "Professional 
A> SP.NET 1.0" but when I try to use it I get an error:

> CS0120: An object reference is required for the nonstatic field, method, 
o> r property 'System.Web.UI.Page.Request'

> I thought the aspx page was the object and Request.whatever would run. I 
h> ave seen this type of reference before. Why doesn't it work for me?

> my code:
<> %@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-
8859-
1> " %>
<> script language="C#" runat="server">
s> tring path = Request.PhysicalApplicationPath;
<> /script>

> <html>
<> head>
<> title>Return the path</title>
<> meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<> /head>
<> body>
<> %= path %>
<> /body>
<> /html>

Message #6 by "Mingkun Goh" <mangokun@h...> on Sat, 6 Jul 2002 15:12:48
Try this

string path = Server.MapPath("")

  Return to Index