Path relative to web site calling a .Net dll

W

W1ld0ne [MCSD]

In VB6 dlls' I could get the path of the calling web site by using the COM+
class library and the ASP class library.

Does anyone have a clue how to do this in VB.Net

The objective is to have an xml file containing some data sitting inside a
web site. Now I want two or more sites to reside on the same server. I want
them to use the same dll's. To open the xml file, I need to supply a path to
it. How would I get this dll to automatically figure out the path to the xml
file.

Below is the function I have tried but It always hits the
System.Web.HttpException, even when it is called from an aspx file on a web
site.

Any help would be appreciated.

Thanks
David Taylor
Private Function BuildXMLFilePath() As String

Try

Try

Dim objWeb As New System.Web.HttpApplication

Dim sAppPath As String = objWeb.Request.ApplicationPath()

objWeb = Nothing

Return (sAppPath & "settings\config.xml")

Catch httpEx As System.Web.HttpException

Return ("e:\Molecule\web\settings\config.xml")

End Try

Catch ex As Exception

ex.Source = TypeName(Me) & ": BuildXMLFilePath(" & Err.Source & ")"

Throw ex

End Try

End Function
 
W

W1ld0ne [MCSD]

I solved it myself. I decided to post the answer hear in case there are any others who also are looking for the same thing.
It's only about two lines of code. I added the complete function so that you can see the implementation.
Private Function BuildXMLFilePath() As String

Try

Dim sAppPath As String

' get the request context '< This is the stuff you would use
Dim _context As System.Web.HttpContext = System.Web.HttpContext.Current '< This is the stuff you would use

' use context to write the trace statement '< This is the stuff you would use
sAppPath = _context.Request.PhysicalApplicationPath() '< This is the stuff you would use

If Len(sAppPath) < 1 Then

sAppPath = "e:\molecule\web\"

End If

_context = Nothing

Return (sAppPath & "settings\config.xml")

Catch ex As Exception

ex.Source = TypeName(Me) & ": BuildXMLFilePath(" & Err.Source & ")"

Throw ex

End Try

End Function

Thanks
David Taylor
 

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

Top