473,327 Members | 2,103 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,327 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 55690
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jon Maz | last post by:
Hi All, I would like to have the following folder structure for an asp.net website: MasterFolder |---\AppRoot | --- webform.aspx | --- web.config | --- global.asax
3
by: Bill Brother | last post by:
Is it possible to retrieve the local full path of an image ( not the url )?
2
by: Jason Huang | last post by:
Hi, Would some one tell me where to find the ASP.Net's root folder? Any help will be appreciated. Jason
1
by: John Dalberg | last post by:
I have an asp.net app that is in a folder which is two levels under the website root folder. The website has a login.aspx which is in the root folder. How do I get the relative path to the web...
4
by: Tee | last post by:
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. ...
4
by: Dots | last post by:
I have a class library with a method called getpath(). I want to be able to get the full path of a folder and write some files to the (my_files_dir) folder. A console application will use this...
4
by: pedestrian via DotNetMonster.com | last post by:
I'm using VB 2005. How to get the full path for "Program Files" folder in Windows, ie. either it is C:\Program Files or D:\Program Files or etc.? How about the full path of "Windows" folder?...
1
by: gujarsachin2001 | last post by:
Hello friends, I have one folder Named as MainFolder on server. I have one more folder named as subfolder inside tht main folder.Now I want to save some pictures in tht folder but at runtime I m...
11
by: rh00667 | last post by:
hi all, i'm confused now. how i can get the full path of an application? if myapp is in a directory which belongs to PATH, argv gives me the first token of cmd line, and not the real path of...
3
by: Rick | last post by:
Hi, Our website used to have all pages in the root folder, and the entry page is "Login.aspx". I was asked to move all pages inside a folder named "Aspx" Is it possible to move also the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.