如何获取已存在的虚拟目录数量及各目录的名称

来源:百度知道 编辑:UC知道 时间:2024/06/17 09:57:59
如题,在C#的asp.net中,如何获取已存在的虚拟目录数量及各目录的名称。特别注意:是不知道目录的名称。
是iis的虚拟目录

public static string VirDirSchemaName = "IIsWebVirtualDir";

public string CreateVirtualDirectory(string nameDirectory, string realPath, string defaultPage)

{

string _serverName = "localhost";

DirectoryEntry _iisServer = new DirectoryEntry("IIS://" + _serverName + "/W3SVC/1");

DirectoryEntry folderRoot = _iisServer.Children.Find("ROOT", VirDirSchemaName);

if (folderRoot == null)

return "IIS 未正常安装";

if (folderRoot.Children == null)

return "IIS 可能未启动";

DirectoryEntry existPath = null;

try

{

existPath = folderRoot.Children.Find(nameDirectory, VirDirSchemaName);

}

catch (Exception e)