• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

Edit the Default IIS Website Path

Hi,

As part of an application I am developing, I need to change the path of the Default IIS website when the software is installed.

This appeared to be quite easy after some searching, but the code I have is returning an "Unknown Error"

Code:

            public static void Configure()
            {
                  DirectoryEntry objDEParent = new DirectoryEntry(@"IIS://localhost/LM/W3SVC/1/ROOT/");

                  objDEParent.Properties["Path"][0] = @"C:\Web";

                  objDEParent.CommitChanges();
            }
Error:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)

All I need to to do is change the Document path for the default IIS website so it points to the folder our software is installed in.

Thanks

Andrew
0
ttnetworks
Asked:
ttnetworks
  • 3
  • 2
1 Solution
 
ihenryCommented:
Try this

               DirectoryEntry objDEParent = new DirectoryEntry(@"IIS://localhost/W3svc/1/Root");
               objDEParent.Properties["Path"].Value = @"C:\Web";
               objDEParent.CommitChanges();
0
 
ttnetworksAuthor Commented:
Hi,

Nope. Reports the same error.

This is on a Windows XP Pro SP2 Machine, which uses IIS 5.1 ?

Thanks

Andrew
0
 
ihenryCommented:
I'm surprised you're still getting the error while I'm able to run the code on the same XP Pro with SP2 and of course IIS 5.1 without any problem.

Just for testing, can you run this code?

DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3svc/1/Root");
Console.WriteLine(de.Properties["Path"].Value);
foreach ( String s in de.Properties.PropertyNames )
{
      Console.WriteLine(s);
}
0
 
ttnetworksAuthor Commented:
Hi,

Yep that code runs OK.

Andrew
0
 
ttnetworksAuthor Commented:
Hi,

All working now, those / make a big difference :-)

Thanks for the help.

Andrew
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now