VirtualPath To PhisicalPath

shlvy

Regular
Joined
Oct 27, 2003
Messages
68
Hi
I have a simple code that i want to convert it from a Virtual Path to Phisical Path:

Sub Page_Load (Source As Object, E as EventArgs)
Dim strConn as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("guestbook.mdb") & ";"
Dim MySQL as string = "SELECT Name, EMail, URL, Comment FROM Guestbook"
Dim MyConn as New OleDBConnection (strConn)
Dim Cmd as New OleDBCommand (MySQL, MyConn)
MyConn.Open ()
rptGuestbook.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
rptGuestbook.DataBind()
End Sub

Can someone help me?
Thank's.
 
Server.MapPath() should work for you...but if your database isn't in the root folder of your project you'd need to supply a full virtual path for it to get it properly "mapped", for ex:

Visual Basic:
Dim sDbPath As String = Server.MapPath("/yourappfolder/yourdatafolder/yourdatabase.mdb")

Paul
 
Relative paths are the devil. Avoid them as you would the plague.

Visual Basic:
Dim databasePath As String = Path.Combine(Application.PhysicalApplicationPath, "database\database.mdb")
 
It's Request.PhysicalApplicationPath

I personally don't use Server.MapPath but it does exist, can be used, and was the context of the original question.

If you're giving a relative virtual path that leads off with a slash it's relative to your virtual root. There's little question about how that path will be interpreted.

I would agree that relative pathing in general can sometimes cause problems.

Paul
 
Last edited:
Back
Top