由于是winform的程序,所以无法使用mappath方法,请问如何给定一个虚拟目录,如何知道它的实际路径呢?

解决方案 »

  1.   

    string sPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    这是一个例子,其他参数你可以查一下sdk
      

  2.   

    看了,不过没有IIS的目录类别
      

  3.   

    如何通过IIS做呢?我感觉应该不存在安全性的问题,如果是window应用程序的话。而且只是做一个路径的转换,应该不复杂阿,只是没有找到合适的方法,有那位大哥了解的说声吧~~~~
      

  4.   

    http://www.disound.com/zblog/post/282.html
      

  5.   

    const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";   DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
       DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);   DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");   //must be end with a '\' 
       tbEntry.Properties["Path"][0] = virtualDirPath;
       tbEntry.Invoke("AppCreate",true);
       tbEntry.Properties["AccessRead"][0] = true;
       tbEntry.Properties["ContentIndexed"][0] = false;
       tbEntry.Properties["DefaultDoc"][0] = "index.asp";
       tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
       tbEntry.Properties["AppIsolated"][0] = 2;
       tbEntry.Properties["AccessScript"][0] = true;   
       tbEntry.Properties["DontLog"][0] = true;   
       
       tbEntry.CommitChanges();
      

  6.   

    除了这个,还有其他的办法吗?这个看起来复杂阿,为了转换个目录要这么麻烦吗?上面这个方法在web中操作的时候好像老说拒绝访问com,为什么呢
      

  7.   

    wmi需要管理员权限,这有个完整的例子
    using System;
    using System.IO;
    using System.Collections;
    using System.DirectoryServices;
    using System.Reflection;
    namespace soccerwrek
    {
     class IISWMI
     {        [STAThread]
      static void Main(string[] args) 
          {
             try
             {
                // retrieve the directory entry for the root of the IIS server            System.DirectoryServices.DirectoryEntry IIS = 
                   new System.DirectoryServices.DirectoryEntry(
                   "IIS://localhost/w3svc/1/root");            // retrieve the list of currently denied IPs            Console.WriteLine(
                    "Retrieving the list of currently denied IPs.");            // get the IPSecurity property            Type typ = IIS.Properties["IPSecurity"][0].GetType();
                object IPSecurity = IIS.Properties["IPSecurity"][0];            // retrieve the IPDeny list from the IPSecurity object
                Array origIPDenyList = (Array) typ.InvokeMember("IPDeny", 
                           BindingFlags.DeclaredOnly | 
                           BindingFlags.Public | BindingFlags.NonPublic | 
                           BindingFlags.Instance | BindingFlags.GetProperty, 
                           null, IPSecurity, null);            // display what was being denied
                foreach(string s in origIPDenyList)
                   Console.WriteLine("Before: " + s);            // check GrantByDefault.  This has to be set to true, 
                // or what we are doing will not work.
                bool bGrantByDefault = (bool) typ.InvokeMember("GrantByDefault", 
                            BindingFlags.DeclaredOnly | 
                            BindingFlags.Public | BindingFlags.NonPublic | 
                            BindingFlags.Instance | BindingFlags.GetProperty, 
                            null, IPSecurity, null);            Console.WriteLine("GrantByDefault = " + bGrantByDefault);
                if(!bGrantByDefault)
                {
                   typ.InvokeMember("GrantByDefault", 
                          BindingFlags.DeclaredOnly | 
                          BindingFlags.Public | BindingFlags.NonPublic | 
                          BindingFlags.Instance | BindingFlags.SetProperty, 
                          null, IPSecurity, new object[] {true});
                }            // update the list of denied IPs.  This is a 
                // complete replace.  If you want to maintain what
                // was already being denied, you need to make sure 
                // those IPs are in here as well.  This area
                // will be where you will most likely modify to
                // your needs as this is just an example.
                Console.WriteLine("Updating the list of denied IPs.");
                object[] newIPDenyList = new object[4];
                newIPDenyList[0] = "192.168.1.1, 255.255.255.255";
                newIPDenyList[1] = "192.168.1.2, 255.255.255.255";
                newIPDenyList[2] = "192.168.1.3, 255.255.255.255";
                newIPDenyList[3] = "192.168.1.4, 255.255.255.255";
                Console.WriteLine("Calling SetProperty");            // add the updated list back to the IPSecurity object
                typ.InvokeMember("IPDeny", 
                         BindingFlags.DeclaredOnly | 
                         BindingFlags.Public | BindingFlags.NonPublic | 
                         BindingFlags.Instance | BindingFlags.SetProperty, 
                         null, IPSecurity, new object[] {newIPDenyList});
                
                IIS.Properties["IPSecurity"][0] = IPSecurity;            
                Console.WriteLine("Commiting the changes.");            // commit the changes
                IIS.CommitChanges();
                IIS.RefreshCache();            // check to see if the update took
                Console.WriteLine("Checking to see if the update took.");
                IPSecurity = IIS.Properties["IPSecurity"][0];
                Array y = (Array) typ.InvokeMember("IPDeny", 
                          BindingFlags.DeclaredOnly | 
                          BindingFlags.Public | BindingFlags.NonPublic | 
                          BindingFlags.Instance | BindingFlags.GetProperty, 
                          null, IPSecurity, null);
                foreach(string s in y)
                   Console.WriteLine("After:  " + s);
             }
             catch (Exception e) 
             {
                Console.WriteLine("Error: " + e.ToString());
             }
      }
     }
    }
      

  8.   

    DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
    DirectoryEntry VirDir = root.Children.Find("虚拟目录名","IIsWebVirtualDir");
    string path = VirDir.Properties["Path"].ToString();