Environment:
- C#
- IIS6 or IIS7 with compatibility mode
.
What I'm trying to do:
Find a particular IIS Web Application and then
- Shut down the parent website
- Add/Replace/Remove files in the physical path of the web application (i.e. applying an update)
- Start up the parent website
.
This is what I've got:
DirectoryEntry IIsEntities = new DirectoryEntry("IIS://localhost/W3SVC");
foreach (DirectoryEntry IIsSite in IIsEntities.Children)
{
if (IIsSite.SchemaClassName == "IIsWebServer")
{
foreach (DirectoryEntry IIsEntity in IIsSite.Children)
{
if (IIsEntity.SchemaClassName == "IIsWebVirtualDir")
{
foreach (DirectoryEntry IIsApp in IIsEntity.Children)
{
yield return new IISWebsite
(
IIsSite.Properties["ServerComment"].Value.ToString(),
IIsApp.Name,
IIsApp.Path,
(ServerState) IIsSite.Properties["ServerState"].Value
);
}
}
}
}
}
This feeds a ComboBox where the user can select the site that they want to be updated. So far, so good. But the IIsApp.Path
gives me a path like IIS://localhost/W3SVC/1/ROOT/Website
which I cannot use with Directory.GetFiles
or similar.
.
What I'm looking for:
A way to update files in a web application by converting the virtual path to a physical path. But maybe I don't even need to convert it if I can use the virtual path to replace files...