views:

135

answers:

3

If I have an ASP.NET code-behind, is there a way to compile the path of that file into the file somehow?

+1  A: 

System.Reflection.Assembly.GetExecutingAssembly() has some good information.

jmaresca
using reflection here is like using a rocket to kill a fly. There are much more efficient ways to get the path and append it.
see_sharp_guy
A: 

(I'm not sure what exactly you're trying to achieve but) you can get the path of the current page at any time, with code like the following (put it into the code-behind of your page):

// this prints the URL to the current page
Response.Write(Request.Url.ToString());
// this prints the server-path (where the page is stored on the server)
Response.Write(Server.MapPath(""));
M4N
A: 

~ refers to your project directory. so if your code behind file is called Default.aspx the path to it would be "~/Default.aspx".

to get the exact full path use "http current context map path". you can open a stream writer and add the path to the aspx file.

see_sharp_guy