471,319 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to get the full path of local IIS root folder?

Tee
Hi,

Can anyone tell me how to get the path of IIS root folder from coding?
Eg: C:\Inetpub\wwwroot.

I would like to detect it via coding as not everyone set it at the default
folder.
Thanks,
Tee
Dec 2 '05 #1
4 14243
Hi,

I think

Server.MapPath ( "/" );

should work for you. You can run that from within your page. Or if you
want to run it from another class, try:

HttpContext.Current.Server.MapPath ( "/" );

-Lenard
Tee wrote:
Hi,

Can anyone tell me how to get the path of IIS root folder from coding?
Eg: C:\Inetpub\wwwroot.

I would like to detect it via coding as not everyone set it at the default
folder.
Thanks,
Tee

Dec 2 '05 #2
Tee
Hi,

That's not a ASP .NET project.

It's a winform project and I need to detect user's local IIS folder.
Thanks.

"Lenard Gunda" <ar***********@freemail.hu> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Hi,

I think

Server.MapPath ( "/" );

should work for you. You can run that from within your page. Or if you
want to run it from another class, try:

HttpContext.Current.Server.MapPath ( "/" );

-Lenard
Tee wrote:
Hi,

Can anyone tell me how to get the path of IIS root folder from coding?
Eg: C:\Inetpub\wwwroot.

I would like to detect it via coding as not everyone set it at the
default folder.
Thanks,
Tee

Dec 2 '05 #3
Tee wrote:
Hi,

That's not a ASP .NET project.

It's a winform project and I need to detect user's local IIS folder.


What do you mean by an IIS folder? If there is more than one site set up
then there may be several folders, possibly on separate disk drives or
computers, containing the served files. Not to mention different virtual
folders in each web site.

Andrew
Dec 2 '05 #4
Hi,

Tee wrote:
Can anyone tell me how to get the path of IIS root folder from coding? Eg:
C:\Inetpub\wwwroot.


First, there may be more than one: Windows Server versions of IIS support
multiple sites. You should enumerate them and ask the user which one they
want to use. Here's some code that does that:

using System.DirectoryServices;

DirectoryEntry iis = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry index in iis.Children)
{
if(index.SchemaClassName == "IIsWebServer")
{
int id = Convert.ToInt32(index.Name);
DirectoryEntry site = new DirectoryEntry("IIS://localhost/W3SVC/" +
id);
string siteName = site.Properties["ServerComment"].Value.ToString();
DirectoryEntry rootVDir = new
DirectoryEntry("IIS://localhost/W3SVC/" + id + "/Root");
string rootPath = rootVDir.Properties["Path"].Value.ToString();
// write site name and root path to console
Console.WriteLine("{0}: \"{1}\" -> {2}", id, siteName, rootPath);
}
}

Secondly, you didn't indicate what you are ultimately trying to do, but it
is worth noting that IIS allows multiple virtual directories under each
site. Much of the site content could well be somewhwere else and not under
the root folder.

If your application is supposed to do something with the entire site, you
way wish to enumerate all virtual directories instead of just getting the
root.

On the other hand, if you want to add your web application to an existing
site, you probably should physically install it to any reasonable location
(user selected or together with the rest of your product), then add it as a
new virtual directory programmatically. That would be much nicer than
depositing it somewhere under the site root.

For more information:

http://msdn.microsoft.com/library/en...6151561f01.asp

--
Chris Priede

Dec 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bill Brother | last post: by
2 posts views Thread by Jason Huang | last post: by
4 posts views Thread by pedestrian via DotNetMonster.com | last post: by
11 posts views Thread by rh00667 | last post: by
3 posts views Thread by Rick | last post: by
reply views Thread by rosydwin | last post: by

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.