473,626 Members | 3,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Current virtual directory from Application_Sta rt ?

Hi

How can I get the application's virtual directory from the
Application_Sta rt method in Global.asax ?

Keep in mind there is no request/response object available yet in this
stage.

Thanks
Saar.

Nov 19 '05 #1
6 5859
Saar Carmi <sa*******@gmai l.com> ha scritto:
Hi

How can I get the application's virtual directory from the
Application_Sta rt method in Global.asax ?
AppDomain.Curre ntDomain.BaseDi rectory
Thanks
Saar.


--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
Nov 19 '05 #2
re:
AppDomain.Curre ntDomain.BaseDi rectory
Nah.

That will return the physical directory, not the virtual dir.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Andrea Zani" <an****@aspital ia.com> wrote in message
news:0u******** ************@tw ister2.libero.i t... Saar Carmi <sa*******@gmai l.com> ha scritto:
Hi

How can I get the application's virtual directory from the
Application_Sta rt method in Global.asax ?


AppDomain.Curre ntDomain.BaseDi rectory
Thanks
Saar.


--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az

Nov 19 '05 #3
You have to get really tricky to get this, Saar, because you can't
retrieve the ServerVariables in the Application_Sta rt global.asax
event, as you correctly point out, because the Request object
is not yet available.

You can kludge the retrieval of the virtual directory by splitting
AppDomain.Curre ntDomain.Dynami cDirectory and adding a "/".

In global.asax :

Sub Application_Sta rt()
Dim MyArray() As String = Split(AppDomain .CurrentDomain. DynamicDirector y, "\")
Application("Ap p_Virtual_Dir") = ("/" & MyArray(6).ToSt ring())
End Sub

In your retrieval page :

<%@ Page Language="VB" EnableViewState ="false" %>
<script runat="server">
Sub Page_Load(obj as object, e as eventargs)
Dim AppDir as String = Application("Ap p_Virtual_Dir")
lblMessage.Text = AppDir
End Sub
</script>
<html>
<body>
<asp:Label id="lblMessage " runat="server"/></asp:Label> <br />
</body>
</html>

---000---

This works because AppDomain.Curre ntDomain.Dynami cDirectory
has a fixed path which includes the virtual directory name, which will
always be in the 7th spot. ( Remember, VB.NET uses zero-based Arrays. )

You could, alternately, split AppDomain.Curre ntDomain.BaseDi rectory
and, if your physical directory is named the same as your virtual directory,
you could retrieve the name and prepend a forward slash to compose your
virtual path.


Splitting AppDomain.Curre ntDomain.BaseDi rectory would need trial and error,
though, because the physical directory may be deep in the wwwroot directory
tree, or even outside the wwwroot tree, and the number of subdirectories might
vary, while the AppDomain.Curre ntDomain.Dynami cDirectory's path is fixed
and the MyArray(6) position will always return just the name of the virtual
directory, needing only the prepended "/" to complete the virtual path.
Good luck !


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Saar Carmi" <sa*******@gmai l.com> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi

How can I get the application's virtual directory from the
Application_Sta rt method in Global.asax ?

Keep in mind there is no request/response object available yet in this
stage.

Thanks
Saar.

Nov 19 '05 #4
Juan T. Llibre <no***********@ nowhere.com> ha scritto:
re:
AppDomain.Curre ntDomain.BaseDi rectory


Nah.

That will return the physical directory, not the virtual dir.


Ops, :)

For read the virtual dir:
dim path as string=AppDomai n.CurrentDomain .FriendlyName
path=path.Subst ring(path.LastI ndexOf("/"))
path=path.Subst ring(0,path.Ind exOf("-"))
Response.write( path)

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
Nov 19 '05 #5
That's better... ;-)

I also wrote a working kludge.
Yours is a bit more elegant, though.

Thanks.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Andrea Zani" <an****@aspital ia.com> wrote in message
news:09******** ************@tw ister1.libero.i t...
Juan T. Llibre <no***********@ nowhere.com> ha scritto:
re:
AppDomain.Curre ntDomain.BaseDi rectory


Nah.

That will return the physical directory, not the virtual dir.


Ops, :)

For read the virtual dir:
dim path as string=AppDomai n.CurrentDomain .FriendlyName
path=path.Subst ring(path.LastI ndexOf("/"))
path=path.Subst ring(0,path.Ind exOf("-"))
Response.write( path)

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az

Nov 19 '05 #6
"Juan T. Llibre" <no***********@ nowhere.com> ha scritto nel messaggio
news:Ox******** ******@TK2MSFTN GP14.phx.gbl...
Sub Application_Sta rt()
Dim MyArray() As String = Split(AppDomain .CurrentDomain. DynamicDirector y,
"\")
Application("Ap p_Virtual_Dir") = ("/" & MyArray(6).ToSt ring())
End Sub


Good solution!

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
Nov 19 '05 #7

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

Similar topics

2
4221
by: Jeffry van de Vuurst | last post by:
Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of you has some ideas about this. I'm using the NetAdvantage component suite from Infragistics for my web applications. When installing they create several virtual
3
25652
by: PHaroZ | last post by:
Hi, I want to retrieve the complete full path to the directory of my current page but i don't find how to do that. For example i want : D:\myWebSite\firstDotNetWebApp\dir1\ I tried "AppDomain.CurrentDomain.BaseDirectory" but it's return only the path to my WebApplication, ex : D:\myWebSite\firstDotNetWebApp\
5
3665
by: Leszek | last post by:
Hello, Could anybody explain what's a difference between a virtual directory and an application root under IIS? I'm a little bit confused. This is mu problem: Let's assume the following directory structure: FileManager (application name a.k.a. virtual directory?)
3
1367
by: Nathan Phelps | last post by:
I realize that I could find my virtual directory using some of the methods in the HttpRequest object, but since the HttpRequest object is not in context during the Application_Start event, I'm at a loss for how to determine what virtual directory my web application is running in. Any suggestions?
0
257
by: Saar Carmi | last post by:
Hi How can I get the application's virtual directory from the Application_Start method in Global.asax ? Keep in mind there is no request/response object available yet in this stage. Thanks Saar.
14
13527
by: gio | last post by:
I have a problem and the solution should works under windows and unix OS. Suppose I have a program ex.c in the directory X (so the current working directory of ex.c is X). Also suppose I have this code fragment: .... char otherpath; char cmd;
2
1354
by: Alwin D | last post by:
Hello, How can I get the current directory of Web Service? Usually my Web services are under Inetpub directory. I would like to write trace file into that place. If I try to trace e.g. C:\Temp directory I usually havenät got permissions to write the trace file. So, do I have special Permissions for wrting trace file from Web Service or
1
1161
by: KUTTAN | last post by:
I want to get the current applications virtual path in global.ascx (event Application_Start()) How can I access that ? Request.ApplicationPath is not valid there :(
6
3515
by: Scott M. | last post by:
I didn't get a resolution to this in my earlier post, so I'll try again: System: Windows XP Pro. (SP2) with IIS installed and running PRIOR to VS 2008 Pro. installation. VS 2008 Pro. (full installation). Installations and testing is all done via an Administrator account. If I simply create a new ASP .NET Web Application Project (WAP) on my local
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8638
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.