Virtual Directory

N

Newbie

I want to determine proramatically from my webform what the virtual
directory path is for my application.

The reason for this is that I want to use some javascript code which needs
to access a file in a subdirectory. This is fine but my component will one
forms which some are in a subdirectory and some will be in the root
directory. This is important when assembling the string needed for the
Window.Open used by javascript link in the page.

So to sum up. I need to know the url for the root of my application.

http://MyHostName/VirtualDirectoryName
 
N

Navin Mishra

How to do the same for a webservice, inside an .asmx file, to get the
virtual directory path ?

Thanks in advance

Navin
 
E

Edwin Knoppert

I'm busy with that as well, it's very annoying resolveurl is that 'hidden'
So far i couldn't find it however, i already wrote a solution.
Please test again, it was a while i used this.

' Returns url based on virtual root, recommended to use for links etc..
' In case of asp:hyperlink or similar objects you better use ~/ instead
like:
'<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/default.aspx">HyperLink</asp:HyperLink>
' This call is ideal for html controls like:
'<a id="A2" href="<%=p.URL_GetRoot("NewFolder1/WebPage.aspx") %>">HTML
HyperLink</a>
Function URL_GetRoot(Optional ByVal sSubFolderFileToAdd As String = "") As
String
Dim Page As System.Web.UI.Page =
CType(System.Web.HttpContext.Current.Handler, System.Web.UI.Page)
sSubFolderFileToAdd = Trim(sSubFolderFileToAdd)
If Left(sSubFolderFileToAdd, 1) = "~" Then sSubFolderFileToAdd =
Mid$(sSubFolderFileToAdd, 2)
If Left(sSubFolderFileToAdd, 1) = "/" Then sSubFolderFileToAdd =
Mid$(sSubFolderFileToAdd, 2)
Return Page.ResolveUrl("~/" & sSubFolderFileToAdd)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,134
Latest member
Lou6777736
Top