473,238 Members | 1,474 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,238 software developers and data experts.

Virtual Directory Detection #2

Thanks to Peter Bromberg for showing me how to detect if a virtual directory
exists. Now I need to determine what folder the virtual directory points to.

For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem to find
any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");

Thanks very much.

Amos
Jan 13 '06 #1
7 4672
Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");


string path = virtualDirectory.Properties["Path"].Value.ToString();
--
Chris Priede
Jan 13 '06 #2
Chris,

This causes an 'Object reference not set to an instance of an object' error.
I don't think "Path" is a valid index into Properties.

AMos.

"Chris Priede" <pr****@panix.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");


string path = virtualDirectory.Properties["Path"].Value.ToString();
--
Chris Priede

Jan 13 '06 #3
Amos,
Chris's code is just fine. if you are getting and object reference exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Amos Soma" wrote:
Chris,

This causes an 'Object reference not set to an instance of an object' error.
I don't think "Path" is a valid index into Properties.

AMos.

"Chris Priede" <pr****@panix.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Amos Soma wrote:
For example, I have the following C# code. It correctly finds the
'MyVirtualDirectory' virtual directory. Now, what method do I call to
determine what folder 'MyVirtualDirectory' points to? I cannot seem
to find any way to do this.

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");


string path = virtualDirectory.Properties["Path"].Value.ToString();
--
Chris Priede


Jan 13 '06 #4
Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is a
test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as being
a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Prop erties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:6B**********************************@microsof t.com...
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Amos Soma" wrote:
Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

"Chris Priede" <pr****@panix.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Amos Soma wrote:
>> For example, I have the following C# code. It correctly finds the
>> 'MyVirtualDirectory' virtual directory. Now, what method do I call to
>> determine what folder 'MyVirtualDirectory' points to? I cannot seem
>> to find any way to do this.
>>
>> DirectoryEntry virtualDirectory = new
>> System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");
>
> string path = virtualDirectory.Properties["Path"].Value.ToString();
>
>
> --
> Chris Priede
>


Jan 13 '06 #5
Peter,

One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.

Amos.

"Amos Soma" <am*********@yahoo.com> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is
a test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as
being a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Prop erties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:6B**********************************@microsof t.com...
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Amos Soma" wrote:
Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

"Chris Priede" <pr****@panix.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Amos Soma wrote:
>> For example, I have the following C# code. It correctly finds the
>> 'MyVirtualDirectory' virtual directory. Now, what method do I call to
>> determine what folder 'MyVirtualDirectory' points to? I cannot seem
>> to find any way to do this.
>>
>> DirectoryEntry virtualDirectory = new
>> System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");
>
> string path = virtualDirectory.Properties["Path"].Value.ToString();
>
>
> --
> Chris Priede
>


Jan 13 '06 #6
I ran your code doing Console.WriteLine on each line of the foreach on a
Windows XP pro machine and here's what I got:

AppIsolated: 0
AppRoot: /LM/W3SVC/1/Root/Aspose.Excel.Demos
AppFriendlyName:
KeyType: IIsWebVirtualDir
Path: C:\Program Files\Aspose\Aspose.Excel\Demos\Aspose.Excel.Demos
AccessFlags: 513
FrontPageWeb: True
AspAllowSessionState: True
AspBufferingOn: True
AspEnableParentPaths: True
AspSessionTimeout: 20
AspScriptTimeout: 90
AspScriptErrorSentToBrowser: True
CacheISAPI: True
AspLogErrorRequests: True
AspExceptionCatchEnable: True
CGITimeout: 300
AspScriptEngineCacheMax: 125
AspMaxDiskTemplateCacheFiles: 1000
AspScriptFileCacheSize: 250
AuthFlags: 5
DirBrowseFlags: 1073741824
DontLog: False
ContentIndexed: True
AppAllowDebugging: True
AppAllowClientDebug: True
AspScriptLanguage: VBScript
AspScriptErrorMessage: An error occurred on the server when processing the
URL.
Please contact the system administrator.
AspDiskTemplateCacheDirectory: C:\WINDOWS\system32\inetsrv\ASP Compiled
Template
s
DefaultDoc: default.aspx,Default.htm,Default.asp
ScriptMaps: System.Object[]
HttpErrors: System.Object[]
CPUCGIEnabled: True
CPUAppEnabled: True
AnonymousPasswordSync: True
AspTrackThreadingModel: False
AspAllowOutOfProcComponents: True
AspEnableAspHtmlFallback: False
AspEnableChunkedEncoding: True
AspEnableTypelibCache: True
AspErrorsToNTLog: False
AspProcessorThreadMax: 25
AspRequestQueueMax: 3000
AspThreadGateEnabled: False
AspThreadGateTimeSlice: 1000
AspThreadGateSleepDelay: 100
AspThreadGateSleepMax: 50
AspThreadGateLoadLow: 50
AspThreadGateLoadHigh: 80
AspQueueTimeout: -1
AspCodepage: 0
AspKeepSessionIDSecure: False
AspEnableApplicationRestart: True
AspQueueConnectionTestTime: 3
AspSessionMax: -1
AspLCID: 2048
AnonymousUserName: IUSR_xxxx
AnonymousUserPass: xxxxxxxxxxx)
Realm: xxxxxx.com
HttpCustomHeaders: X-Powered-By: ASP.NET
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Amos Soma" wrote:
Peter,

One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.

Amos.

"Amos Soma" <am*********@yahoo.com> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Peter,

I don't think Chris's code is fine, or I am doing something wrong. Here is
a test method I wrote.
This method works fine up until the 'path =
virtualDirectory.Properties["Path"].Value.ToString()' line.
It then crashes. Alos, the 'foreach' statement does not show 'Path' as
being a property of 'Properties'.

Thanks very much.
private void TestVirtualDirectory()
{

DirectoryEntry virtualDirectory = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/SDBSClientUpdate");
System.DirectoryServices.PropertyCollection collection =
virtualDirectory.Properties;
string path;

foreach(string name in collection.PropertyNames)
MessageBox.Show(
string.Format("{0}:{1}",name,virtualDirectory.Prop erties[name].Value.ToString())
);

path = virtualDirectory.Properties["Path"].Value.ToString();
MessageBox.Show(path);
}
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:6B**********************************@microsof t.com...
Amos,
Chris's code is just fine. if you are getting and object reference
exception
that's because your method call to DirectoryEntry isn't returning a
DirectoryEntry object.
Check your IIS pathing.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Amos Soma" wrote:

Chris,

This causes an 'Object reference not set to an instance of an object'
error.
I don't think "Path" is a valid index into Properties.

AMos.

"Chris Priede" <pr****@panix.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Amos Soma wrote:
>> For example, I have the following C# code. It correctly finds the
>> 'MyVirtualDirectory' virtual directory. Now, what method do I call to
>> determine what folder 'MyVirtualDirectory' points to? I cannot seem
>> to find any way to do this.
>>
>> DirectoryEntry virtualDirectory = new
>> System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/MyVirtualDirectory");
>
> string path = virtualDirectory.Properties["Path"].Value.ToString();
>
>
> --
> Chris Priede
>



Jan 13 '06 #7
Hi,

Amos Soma wrote:
One thing I have learned. If the code below is run on a Windows XP
Professional box, an exception is thrown. If it's run on a Windows 2003
Server box, it works correctly.


What is the service pack level of your XP installation?

--
Chris Priede
Jan 14 '06 #8

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

Similar topics

3
by: Zenobia | last post by:
I copy an application to wwwroot: wwwroot +--- myApp +--- common | +--- images | default.asp global.asa
2
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...
5
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...
2
by: Danny Miller | last post by:
Hi there, I'm facing a problem that is driving me nuts. The scenario is as follows: 1) Create an empty directory structure e.g. C:\Dev1\TestWebApp 2) Map a virtual directory e.g. TestWebApp...
4
by: david | last post by:
I basically use the following code to display the directory and file names in the WWWROOT, but can not show the virtual directory. ---- Dim path As String = Server.MapPath(x) Dim di As...
2
by: Amos Soma | last post by:
Anyone know how I can programatically detect whether a virtual directory exists on a machine my app is running on? And how to retrieve information about that virtual directory? Thanks very much....
8
by: wally | last post by:
There is a brilliant application that allows you to wrap your EXE and all associated DLLs, OCXs, etc. into a single executable and run the executable on Windows OSs with no install and nor...
6
by: ManagedCoder | last post by:
Hi, My requirement is as follows: I need to set the HttpExpires (enable content expiration - set to 7 days) on a folder within a virtual directory. I have been able to set the HttpExpires...
6
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...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.