怎样在一个程序集内部写一段代码来知道这个程序集在运行时的路径?

解决方案 »

  1.   

    试试:
    using System.Reflection;Response.Write(Assembly.GetExecutingAssembly().GetName().CodeBase);
      

  2.   

    imports system.reflection
    觉得可以在这个程序集里的一个类中写个方法用反射来获得自己的路径,大概使用的方法就是codebase或者location
      

  3.   

    System.IO.DirectoryInfo sd = new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory()) ;
      

  4.   

    Environment.CurrentDirectory
    Application.ExecutablePath
    System.Windows.Forms.Application.StartUpPath
      

  5.   

    用Assembly.GetExecutingAssembly().GetName().CodeBase
    得到的路径file:///c:/inetpub/wwwroot/ws/WebService1/bin/dbconf.xml无法使用Application.ExecutablePath
    System.Windows.Forms.Application.StartUpPath
    以上两种方式只适合在CS下使用,BS下就不行System.IO.DirectoryInfo sd = new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory()) ;
    在BS下得到的是SYSTEM32路径
      

  6.   

    MessageBox.Show(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
      

  7.   

    用"应用程序域"可以解决
    using System.AppDomain;
    ......string strAddress = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
    不知道是不是楼主想要的
      

  8.   

    感觉这个问题,泡泡的应该是正解,或者System.Reflection.Assembly.GetAssembly( this.GetType() ).Location也可以.