如果我使用Request.PhysicalApplicationPath,只能读取到当前虚拟目录的物理路径,使用DirectoryEntry对象也未有读取IIS的根目录路径的参数,请问各位大虾如何解决这个问题啊..

解决方案 »

  1.   

    Server.MapPath("../虚拟目录名称")
      

  2.   

    string entPath = String.Format("IIS://{0}/w3svc", HostName);
    DirectoryEntry ent=new DirectoryEntry(entPath, UserName, Password, AuthenticationTypes.Secure);
    string a=ent.Properties["Path"].Value
      

  3.   

    楼上的,我将你的代码改为:
    string entPath = String.Format("IIS://{0}/w3svc", "192.168.1.16");
    DirectoryEntry ent=new DirectoryEntry(entPath);
    string a=ent.Properties["Path"].Value.ToString();出这样的错误信息啊........
    Access is denied 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Access is deniedSource Error: 
    Line 107: string entPath = String.Format("IIS://{0}/w3svc", "192.168.1.16");
    Line 108: DirectoryEntry ent=new DirectoryEntry(entPath);
    Line 109: string a=ent.Properties["Path"].Value.ToString();
    Line 110:
    Line 111:
     
      

  4.   

    文件路径问题 
     
    1。  filename="ErrorMessage.txt";   得到//“C:\WINNT\system32\ErrorMessage.txt”
     
    2。  得到www路径 (/)=(c:\inetpub\wwwroot\)
         filename=Server.MapPath("/msg/ErrorMessage.txt");    //c:\inetpub\wwwroot\msg\ErrorMessage.txt
         filename=Server.MapPath("/") +"msg/ErrorMessage.txt";
         filename=Server.MapPath("../msg/ErrorMessage.txt");
     
    3。 得到当前虚拟根目录的路径 ( ~/)
         filename=Server.MapPath("~/msg/ErrorMessage.txt");//D:\公司项目\PowerMis\Web\msg\ErrorMessage.txt
         filename=HttpRuntime.AppDomainAppPath;
    4.  当前路径(相对)( ./)
        filename=Server.MapPath("./ErrorMessage.txt");D:\公司项目\PowerMis\Web\  ErrorMessage.txt
        filename=Server.MapPath(Request.ApplicationPath);
        filename=Server.MapPath(".");
    5   /Web
        filename=HttpRuntime.AppDomainAppVirtualPath; 
        filename=Request.ApplicationPath;