473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Path relative to web site calling a .Net dll

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
Nov 20 '05 #1
1 3577
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


"W1ld0ne [MCSD]" <W1*******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeff Wagner | last post by:
Is it possible to append a new Path to some file permanently? It seems like a sys.path.append('/my/new/path') statement is temporary. In other words, where and in what file on a Win32 box or...
1
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not...
6
by: David W. Simmonds | last post by:
I know that I can create an Image object by using a path like C:\MyPictures\pic.jpg, but how can I create an Image object by using a path like /MyPictures/pic.jpg where the path is relative to the...
8
by: dw | last post by:
Hello, all. I have a site that I'm testing on my LOCALHOST and also on a remote server, depending on whether I'm at work or at home. I don't want the OLEDBDATAAdapter to be pointing to the remote...
6
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data...
4
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
2
by: Jordan Richard | last post by:
Put another way, is there any way I can tell ASP.NET to convert a path (imbedded in a string variable, "~/images/some_image.gif") to a root-relative path, that the client will understand, for the...
0
by: flipdoubt | last post by:
Are there any specialized methods for determining whether a path or UNC points to a location within a site's web directories? Are there any methods for turning an absolute path into a relative URL?...
2
by: D Godwin | last post by:
This is probably more of a straight HTML question, but here goes: I want to change from http to https during a form submit. This it pretty straightforward with a complete path...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.