Reputation: 3199
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?
Upvotes: 0
Views: 1129
Reputation: 45083
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;
Upvotes: 2