I came across a situation , where I had multiple folders in my application (Lottery,Single DOnation ,Multiple Donation).Each of these folders contained multiple .aspx files with same name with hierarchy as shown below
The logic was written so that based on the application path, the .aspx pages relevant to each folder were displayed .Although much of the content (server control, user control etc.) in most of these pages were identical , there were scenarios where I had to enable/disable a control based on the root folder .For instance , if it is the index.aspx and I am displaying the index page under Single Donation ,I do not want to display the mysampletextbox.text .
The trick here is to strip out the immediate parent folder from TemplateSourceDirectory property of an aspx page. This can be done in 3 simple lines of code
‘gives you the directory path for your current page i.e “/Application/Donations/Lottery” As string in my case
Dim myTempSourceDir As String = Page.TemplateSourceDirectory
‘Following 2 lines of code is a simple logic to Strip off the “Lottery” part from the above string
Dim myTrimIndex As Integer = myTempSourceDir.LastIndexOf(“/”)
Dim myRootFolder As String = myTempSourceDir.Remove(0, 24)
If myRootFolder = (“Lottery”) Then
mysampletextbox.Visible = True
mysampletextbox.Visible = False
Happy Coding 🙂 !!!!!