Saturday, March 24, 2012

MapPath member in page class

hello everyone,

I am new to Asp.NET and I have a small concern.

Response.Output.Write(
"Physical path of page is : {0}<br>",
MapPath("excerise1.aspx"));

This stmt should actuallu return the actual physicla path.. A path would be returned if I create an excerise1.aspx project...But no matter what project i create its returning a physical path..How is this happening..
It should only return the path if I create a project right? what does that <br> mean?

And moreover what does <script runat=server> .... </script> mean?Second question first ... script runat="server" means that the code will run on the server (not as client script in the browser). The Response.Write method is a server-side function that puts information into the stream sent from the server to the browser.

As for MapPath, it resolves a given file or folder name and returns the actual physical location of that file or folder on the server. Exercise1.aspx isn't a project, it's the name of a file (an ASP.NET page). I'm a little confused by your question -- you say that it should return the actual physical path, but then you say it's returning the physical path. What are you hoping for it to return and what is it actually returning instead?

The br tag in the middle will be injected as a literal into the stream, hence will generate a linebreak in the browser.
Hello Mike

Thankx a lot..

I was referring to actual path not the physical path...

regards
sekhar
MapPath's purpose is to return a physical path.
regardless of what virtual folder you point it to, you're going to get a physical path back.

sounds like it is working correctly.
You might find this useful (?):

http://www.mikepope.com/blog/DisplayBlog.aspx?permalink=506

Also, Fritz Onion has a good article on various ways to work with paths here:

Understanding Paths in ASP.NET

0 comments:

Post a Comment