Get current path in VB class?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngvb' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Peter Brunone
Group,

    I'm using a VB.Net dll in a web app, and I'd like to be able to get a
representation of the path to that particular \bin directory (well, to the
folder right above it), and I can't figure out how. I can get all kinds of
neat information about the system through GetEnvironmentVariables, but
nothing that just tells me the current path.
    Of course in a winform this would be a piece of cake, but can anyone tell
me how to get it in a class library? System.IO.Path.GetFullPath("\") just
gives me "C:\", which of course doesn't help much... any constructive
suggestions would be appreciated.

Cheers,

Peter

Reply to this message...
 
    
=?iso-8859-1?Q?Andr=E9s_G_Vettori?=
This code will do the trick...
Add a new class and name it ThisApp, then copy the following code
inside:

Option Explicit On=20
Option Strict On
Imports System
Imports System.IO

Class ThisApp
Private Shared mExeName As String =3D
Dir(System.Reflection.Assembly.GetExecutingAssembly.Location)
Private Shared mPath As String =3D
System.Reflection.Assembly.GetExecutingAssembly.Location
Private Shared mAppPath As String =3D Path.GetFullPath((Left(mPath,
(Len(mPath) - Len(mExeName)))))
Private Shared mExeVersion As String =3D
CStr(System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection
.Assembly.GetExecutingAssembly.Location).FileVersion)
Public Shared ReadOnly Property AppPath() As String
Get
Return mAppPath
End Get
End Property
Public Shared ReadOnly Property ExeName() As String
Get
Return mExeName
End Get
End Property
Public Shared ReadOnly Property ExeVersion() As String
Get
Return mExeVersion
End Get
End Property
End Class

Enjoy!

Andr=E9s G Vettori
MCSE/MCSD/MCT
Thawte Notary
Click here to reveal e-mail address
Phone +54(11) 15-4914-2560
Obten=E9 tu certificado digital totalmente gratis en
http://www.thawte.com/getinfo/programs/wot/about.html
=20

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, July 02, 2002 9:56 PM
To: aspngvb
Subject: [aspngvb] Get current path in VB class?

Group,

    I'm using a VB.Net dll in a web app, and I'd like to be able to
get a
representation of the path to that particular \bin directory (well, to
the
folder right above it), and I can't figure out how. I can get all kinds
of
neat information about the system through GetEnvironmentVariables, but
nothing that just tells me the current path.
    Of course in a winform this would be a piece of cake, but can
anyone tell
me how to get it in a class library? System.IO.Path.GetFullPath("\")
just
gives me "C:\", which of course doesn't help much... any constructive
suggestions would be appreciated.

Cheers,

Peter

| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT

Reply to this message...
 
    
Darren Neimke
How about using Server.MapPath

Dim myPath As String =3D Server.MapPath("/bin")
Response.Write("Bin is located at " & myPath)

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 03, 2002 10:26 AM
To: aspngvb
Subject: [aspngvb] Get current path in VB class?

Group,

    I'm using a VB.Net dll in a web app, and I'd like to be able to
get a representation of the path to that particular \bin directory
(well, to the folder right above it), and I can't figure out how. I can
get all kinds of neat information about the system through
GetEnvironmentVariables, but nothing that just tells me the current
path.
    Of course in a winform this would be a piece of cake, but can
anyone tell me how to get it in a class library?
System.IO.Path.GetFullPath("\") just gives me "C:\", which of course
doesn't help much... any constructive suggestions would be appreciated.

Cheers,

Peter

| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT

Reply to this message...
 
    
Darren Neimke
Sorry Peter, I'm a dork! I didn't read your question correctly the
first time round.

Basically you need to get a handle to the current ASP.NET context

Here's some *tested* code :-)

-------------------------------------
    TestClass.vb
-------------------------------------

    Public Class TestClass

        Public Function GetFolderPath(ByVal sPath As String) As
String

        ' You need to get a handle to the current
ASP.NET context
        Dim myPath As String =3D
System.Web.HttpContext.Current.Server.MapPath(sPath)
        Return myPath

        End Function

    End Class

-------------------------------------

-------------------------------------
    Consumer.aspx
-------------------------------------

    Dim myObj As New TestClass()
    Dim folderPath As String =3D myObj.GetFolderPath("\bin")
    Response.Write(folderPath)

-------------------------------------

Reply to this message...
 
    
Peter Brunone
Andrés,

    Thanks for contributing. Unfortunately, this seems to return a directory
where temporary asp.net files are stored as part of the framework's
compilation system for web pages, rather than the directory from which the
actual files run.
    Still good stuff to know, though.

Cheers,

Peter

|-----Original Message-----
|From: Andrés G Vettori [mailto:Click here to reveal e-mail address]
|
|This code will do the trick...
|Add a new class and name it ThisApp, then copy the following code
|inside:
|
|Option Explicit On
|Option Strict On
|Imports System
|Imports System.IO
|
|Class ThisApp
| Private Shared mExeName As String =
|Dir(System.Reflection.Assembly.GetExecutingAssembly.Location)
| Private Shared mPath As String =
|System.Reflection.Assembly.GetExecutingAssembly.Location
| Private Shared mAppPath As String = Path.GetFullPath((Left(mPath,
|(Len(mPath) - Len(mExeName)))))
| Private Shared mExeVersion As String =
|CStr(System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection
|.Assembly.GetExecutingAssembly.Location).FileVersion)
| Public Shared ReadOnly Property AppPath() As String
| Get
| Return mAppPath
| End Get
| End Property
| Public Shared ReadOnly Property ExeName() As String
| Get
| Return mExeName
| End Get
| End Property
| Public Shared ReadOnly Property ExeVersion() As String
| Get
| Return mExeVersion
| End Get
| End Property
|End Class
|
|Enjoy!
|
|Andrés G Vettori
|
|-----Original Message-----
|From: Peter Brunone [mailto:Click here to reveal e-mail address]
|
|Group,
|
|    I'm using a VB.Net dll in a web app, and I'd like to be able to
|get a
|representation of the path to that particular \bin directory (well, to
|the
|folder right above it), and I can't figure out how. I can get all kinds
|of
|neat information about the system through GetEnvironmentVariables, but
|nothing that just tells me the current path.
|    Of course in a winform this would be a piece of cake, but can
|anyone tell
|me how to get it in a class library? System.IO.Path.GetFullPath("\")
|just
|gives me "C:\", which of course doesn't help much... any constructive
|suggestions would be appreciated.
|
|Cheers,
|
|Peter
|

Reply to this message...
 
    
Peter Brunone
Darren,

    Thanks for taking time to write and test some code! Unfortunately, this
still doesn't seem to work in a dll (Visual Studio claims that Web isn't a
member of System and won't even let me compile)... and it looked like such a
good idea, too.
    The whole purpose of this exercise was to ascertain the version of the site
(Dev, Test, or Production) in order to pick the correct connection string
which I'm keeping within the class. Since they're in separate applications
(and I can't seem to merely get the IIS application name either), I can just
set up a different anonymous user for each site... and I should probably do
so anyway.
    Feel free to let me know if there's another method I should consider.

Cheers,

Peter

|-----Original Message-----
|From: Darren Neimke [mailto:Click here to reveal e-mail address]
|
|Sorry Peter, I'm a dork! I didn't read your question correctly the
|first time round.
|
|Basically you need to get a handle to the current ASP.NET context
|
|Here's some *tested* code :-)
|
|
|-------------------------------------
|    TestClass.vb
|-------------------------------------
|
|    Public Class TestClass
|
|         Public Function GetFolderPath(ByVal sPath As String) As
|String
|
|         ' You need to get a handle to the current
|ASP.NET context
|         Dim myPath As String =
|System.Web.HttpContext.Current.Server.MapPath(sPath)
|         Return myPath
|
|         End Function
|
|
|    End Class
|
|-------------------------------------
|
|
|
|-------------------------------------
|    Consumer.aspx
|-------------------------------------
|
|    Dim myObj As New TestClass()
|    Dim folderPath As String = myObj.GetFolderPath("\bin")
|    Response.Write(folderPath)
|
|-------------------------------------
|

Reply to this message...
 
    
Duncan Mackenzie (VIP)
You need to add a reference to System.Web.dll to compile Darren's code

=20
Duncan Mackenzie (MSDN)
Click here to reveal e-mail address
www.duncanmackenzie.net
=20
=20

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, July 02, 2002 10:05 PM
To: aspngvb
Subject: [aspngvb] RE: Get current path in VB class?

Darren,

    Thanks for taking time to write and test some code!
Unfortunately, this still doesn't seem to work in a dll (Visual Studio
claims that Web isn't a member of System and won't even let me
compile)... and it looked like such a good idea, too.
    The whole purpose of this exercise was to ascertain the version
of the site (Dev, Test, or Production) in order to pick the correct
connection string which I'm keeping within the class. Since they're in
separate applications (and I can't seem to merely get the IIS
application name either), I can just set up a different anonymous user
for each site... and I should probably do so anyway.
    Feel free to let me know if there's another method I should
consider.

Cheers,

Peter

|-----Original Message-----
|From: Darren Neimke [mailto:Click here to reveal e-mail address]
|
|Sorry Peter, I'm a dork! I didn't read your question correctly the=20
|first time round.
|
|Basically you need to get a handle to the current ASP.NET context
|
|Here's some *tested* code :-)
|
|
|-------------------------------------
|    TestClass.vb
|-------------------------------------
|
|    Public Class TestClass
|
|         Public Function GetFolderPath(ByVal sPath As String) As
String
|
|         ' You need to get a handle to the current
|ASP.NET context
|         Dim myPath As String =3D
|System.Web.HttpContext.Current.Server.MapPath(sPath)
|         Return myPath
|
|         End Function
|
|
|    End Class
|
|-------------------------------------
|
|
|
|-------------------------------------
|    Consumer.aspx
|-------------------------------------
|
|    Dim myObj As New TestClass()
|    Dim folderPath As String =3D myObj.GetFolderPath("\bin")
|    Response.Write(folderPath)
|
|-------------------------------------
|

| [aspngvb] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT

Reply to this message...
 
    
Darren Neimke
> You need to add a reference to System.Web.dll to compile Darren's code

Wooops! Thanks for that catch Duncan.

Sorry I hadn't actually considered what references you'd need to keep
the compiler happy :-) I didn't notice the error becase - as a
self-imposed standard - I automatically insert the following statements
at the top of every class I create in Visual Studio:

    Option Strict On

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.IO
    Imports System.Text
    Imports System.Web
    Imports System.Web.UI

One thing that I did omit to mention is that you may want to wrap the
assignment in a test like so:

    Dim myPath As String =3D ""

    If Not System.Web.HttpContext Is Nothing Then
    myPath =3D System.Web.HttpContext.Current.Server.MapPath(sPath)
    End If
Return myPath

Refer this post for more details...

    http://www.asp.net/Forums/ShowPost.aspx?tabindex=3D1&PostID=3D6587

Reply to this message...
 
    
Peter Brunone
But why would you need a reference if you're providing the fully qualified namespace tree already? System.Web.HttpContext.Current.Server doesn't rely on an import statement because it explicitly refers to the requested class.
For what it's worth, I tried this anyway, but VS.Net won't even let me import System.Web into my class; it claims that it can't find the namespace or type 'Web'.
Even stranger, when I try Server.Mappath("\bin") from the .aspx file, I get a very curious result. My three IIS applications are under the E:\Webroot\CentralWeb directory (the site root); the applications (and subdirectories) are called Dev, Test, and Prod. What I get back from the mappath command, though, is E:\Webroot\CentralWeb\bin; the \Dev part is completely missing, and what's worse, that path doesn't even exist!
My final solution to this (for now) is to use Page.TemplateSourceDirectory and pass that value to the New() method of my object, which then determines which connection string to use. As always, let me know if there's something I just totally missed.
Cheers,
Peter
Darren Neimke <Click here to reveal e-mail address> wrote: > You need to add a reference to System.Web.dll to compile Darren's code

Wooops! Thanks for that catch Duncan.

Sorry I hadn't actually considered what references you'd need to keep
the compiler happy :-) I didn't notice the error becase - as a
self-imposed standard - I automatically insert the following statements
at the top of every class I create in Visual Studio:

Option Strict On

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.UI

One thing that I did omit to mention is that you may want to wrap the
assignment in a test like so:

Dim myPath As String = ""

If Not System.Web.HttpContext Is Nothing Then
myPath = System.Web.HttpContext.Current.Server.MapPath(sPath)
End If
Return myPath

Refer this post for more details...

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=6587

---------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access
Reply to this message...
 
    
Michael Wells
Does Server.Mappath("/bin") do the same? The backslash in your example
may be causing confusion.

-----Original Message-----
From: Peter Brunone [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 03, 2002 2:07 PM
To: aspngvb
Subject: [aspngvb] RE: Get current path in VB class?

But why would you need a reference if you're providing the fully
qualified namespace tree already? System.Web.HttpContext.Current.Server
doesn't rely on an import statement because it explicitly refers to the
requested class.=20

For what it's worth, I tried this anyway, but VS.Net won't even let
me import System.Web into my class; it claims that it can't find the
namespace or type 'Web'.=20

Even stranger, when I try Server.Mappath("\bin") from the .aspx
file, I get a very curious result. My three IIS applications are under
the E:\Webroot\CentralWeb directory (the site root); the applications
(and subdirectories) are called Dev, Test, and Prod. What I get back
from the mappath command, though, is E:\Webroot\CentralWeb\bin; the \Dev
part is completely missing, and what's worse, that path doesn't even
exist!=20

My final solution to this (for now) is to use
Page.TemplateSourceDirectory and pass that value to the New() method of
my object, which then determines which connection string to use. As
always, let me know if there's something I just totally missed.=20

Cheers,=20

Peter=20

Darren Neimke <Click here to reveal e-mail address> wrote:=20

> You need to add a reference to System.Web.dll to compile Darren's code

Wooops! Thanks for that catch Duncan.

Sorry I hadn't actually considered what references you'd need to keep
the compiler happy :-) I didn't notice the error becase - as a
self-imposed standard - I automatically insert the following statements
at the top of every class I create in Visual Studio:

Option Strict On

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.UI

One thing that I did omit to mention is that you may want to wrap the
assignment in a test like so:

Dim myPath As String =3D ""

If Not System.Web.HttpContext Is Nothing Then
myPath =3D System.Web.HttpContext.Current.Server.MapPath(sPath)
End If
Return myPath

Refer this post for more details...

http://www.asp.net/Forums/ShowPost.aspx?tabindex=3D1&PostID=3D6587

_____ =20

Do You Yahoo!?
New! SBC Yahoo! Dial
<http://pa.yahoo.com/*http://rd.yahoo.com/sbcyahoo/consumer/evt=3D640/*ht=
t
p://sbc.yahoo.com> - 1st Month Free & unlimited access | [aspngvb]
member Click here to reveal e-mail address =3D YOUR ID |
http://www.asplists.com/asplists/aspngvb.asp =3D JOIN/QUIT

Reply to this message...
 
    
Darren Neimke
UGV0ZXIsDQogDQpBcmUgeW91IGluY2x1ZGluZyBhIHJlZmVyZW5jZSB0byB0aGUgU3lzdGVtLldl
YiBkbGwgaW4geW91ciBwcm9qZWN0Pw0KIA0KIA0KLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0g
DQpGcm9tOiBQZXRlciBCcnVub25lIFttYWlsdG86cGV0ZXJfYnJ1bm9uZUB5YWhvby5jb21dIA0K
U2VudDogVGh1IDQvMDcvMjAwMiA0OjM3IEFNIA0KVG86IGFzcG5ndmIgDQpDYzogDQpTdWJqZWN0
OiBbYX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25zdW1lci9ldnQ9NjQwLypodHRwOi8vc2JjLnlhaG9vLmNvbT4gIC0gMXN0IE1v
bnRoIEZyZWUgJiB1bmxpbWl0ZWQgYWNjZXNzIHwgW2FzcG5ndmJdIG1lbWJlciBkYXJyZW4ubmVp
bWtlQHNkbS5jb20uYXUgPSBZT1VSIElEIHwgaHR0cDovL3d3dy5hc3BsaXN0cy5jb20vYXNwbGlz
dHMvYXNwbmd2Yi5hc3AgPSBKT0lOL1FVSVQNCg0K
Reply to this message...
 
    
Peter Brunone

    Yes. I've tried it just about every sane way I can think of, used values
like "/booga" and "\wooga", and it always just slaps whatever I provide on
to the end of that base path. The current solution
(Page.TemplateSourceDirectory) works fine for me, though...

-Peter

|-----Original Message-----
|From: Michael Wells [mailto:Click here to reveal e-mail address]
|
|Does Server.Mappath("/bin") do the same? The backslash in your example
|may be causing confusion.
|
|-----Original Message-----
|From: Peter Brunone [mailto:Click here to reveal e-mail address]
|
| But why would you need a reference if you're providing the fully
|qualified namespace tree already? System.Web.HttpContext.Current.Server
|doesn't rely on an import statement because it explicitly refers to the
|requested class.
|
|
| For what it's worth, I tried this anyway, but VS.Net won't even let
|me import System.Web into my class; it claims that it can't find the
|namespace or type 'Web'.
|
|
| Even stranger, when I try Server.Mappath("\bin") from the .aspx
|file, I get a very curious result. My three IIS applications are under
|the E:\Webroot\CentralWeb directory (the site root); the applications
|(and subdirectories) are called Dev, Test, and Prod. What I get back
|from the mappath command, though, is E:\Webroot\CentralWeb\bin; the \Dev
|part is completely missing, and what's worse, that path doesn't even
|exist!
|
|
| My final solution to this (for now) is to use
|Page.TemplateSourceDirectory and pass that value to the New() method of
|my object, which then determines which connection string to use. As
|always, let me know if there's something I just totally missed.
|
|
|Cheers,
|
|
|Peter
|
|
| Darren Neimke <Click here to reveal e-mail address> wrote:
|
|
|> You need to add a reference to System.Web.dll to compile Darren's code
|
|Wooops! Thanks for that catch Duncan.
|
|Sorry I hadn't actually considered what references you'd need to keep
|the compiler happy :-) I didn't notice the error becase - as a
|self-imposed standard - I automatically insert the following statements
|at the top of every class I create in Visual Studio:
|
|Option Strict On
|
|Imports System
|Imports System.Data
|Imports System.Data.SqlClient
|Imports System.IO
|Imports System.Text
|Imports System.Web
|Imports System.Web.UI
|
|
|One thing that I did omit to mention is that you may want to wrap the
|assignment in a test like so:
|
|Dim myPath As String = ""
|
|If Not System.Web.HttpContext Is Nothing Then
|myPath = System.Web.HttpContext.Current.Server.MapPath(sPath)
|End If
|Return myPath
|
|Refer this post for more details...
|
|http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=6587

Reply to this message...
 
    
elie khoury
i had the same problem as yours, so this is it solution, but you should test it from your browser as you normally do not from visual studio.

Public ReadOnly Property Version() As String
Get
Try
Return System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Web.HttpContext.Current.Server.MapPath("bin\test.dll")).FileVersion
Catch ex As Exception
Return "1.0.0.0"
End Try
End Get
End Property
--------------------------------
From: Elio
Reply to this message...
 
 
System.Diagnostics.FileVersionInfo
System.IO.Path
System.Reflection.Assembly
System.Web.HttpContext
System.Web.UI.Page




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com