MStodd
MStodd

Reputation: 4746

C# .NET: Can I compile a file's file path into the file?

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

Upvotes: 0

Views: 239

Answers (3)

jmaresca
jmaresca

Reputation: 61

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

Upvotes: 1

see_sharp_guy
see_sharp_guy

Reputation: 239

~ 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.

Upvotes: 0

M4N
M4N

Reputation: 96551

(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(""));

Upvotes: 1

Related Questions