DirectoryEntry.Properties["Path"].Value.ToString(); IIS7 issue. C#


Currently getting Unknown error (0x80005000) - Linked to "COM Exception" in C# when running the following code string virtualDirectory = GetVirtualDirPath("IIS://localhost", "1", reportUrl);

static string GetVirtualDirPath(string iisHost,
                                 string siteName, string vdName)
        string adsiPath = iisHost + "/W3SVC/" + siteName + "/Root/test/" + vdName;

            DirectoryEntry entry = new DirectoryEntry(adsiPath);
            return entry.Properties["Path"].Value.ToString();
        catch (Exception ex)
            // If Virtual Directory is not found,
            // it will throw exception.
            return "";

        return "";

I have setup "share" as a Virtual Directory inside "/test" (http://localhost/test/share) and tried giving that folder relevant permissions.

I have read that this only works in IIS6 and Not IIS7? If so, what is the equivalent code?


1 Answer


IIS7 now exposes a managed management API, information of which can be found here.

More specifically, there are classes to facilitate management of virtual directories.

var iis = new ServerManager();
var site = iis.Sites["SiteName"];
var application = site.Applications["ApplicationName"];
var directories = application.VirtualDirectories;
//proceed to determine the physical path of appropriate directory
var path = directories[0].Path;
answered on Stack Overflow Dec 8, 2011 by Grant Thomas • edited Dec 8, 2011 by Grant Thomas

User contributions licensed under CC BY-SA 3.0