tags:

views:

151

answers:

2

Is it possible to figure out the current ViewContext's VirtualPath eg

~/Views/Company/Create.aspx

+2  A: 

I think this is what you're after:

((WebFormView) ViewContext.View).ViewPath

Obviously this only works if your using the standard web form view engine (which based off the wording of your question, you are). I.e. the ViewContext.View returns an IView, which may not be a WebFormView if you're using a different view engine.

Edit: By the way, I have tested the above code and it definitely returns the path as a virtual path (and not an absolute or app relative path, like I initially assumed it might). I.e. it gives you a value like this:

~/Views/Company/Create.aspx
Alconja
This worked thank you :)
bleevo
A: 

You can use this code to get the virtual path,

<%= HttpRuntime.AppDomainAppVirtualPath %>
Tony Borf