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

0

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;

        try
        {
            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?

c#
asp.net
iis-7
iis-6
iis-7.5

1 Answer

2

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