0

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...

EasierSaidThanDone
  • 1,877
  • 4
  • 20
  • 29
  • check this http://stackoverflow.com/questions/5431713/how-to-get-the-iis-virtual-dir-web-applications-physical-paths-with-c-sharp-c – Damith Aug 29 '13 at 03:16

1 Answers1

1

Finally got it...

        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher("root\\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDirSetting");

        foreach (ManagementObject queryObj in searcher.Get())
        {
           result.Add(queryObj["Path"]);
        }
EasierSaidThanDone
  • 1,877
  • 4
  • 20
  • 29