473,249 Members | 1,408 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,249 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 15033
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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.