c#获取当前应用程序所在路径

 对于Windows程序 和Web 应用程序来说,他们运行的路径是不一样的,所以关键是判断当前运行的程序是哪种程序.于是我们可以使用如下的代码
 string path = "";
           
if (System.Environment.CurrentDirectory == AppDomain.CurrentDomain.BaseDirectory)//Windows应用程序则相等
           {
               path 
= AppDomain.CurrentDomain.BaseDirectory;
           }

           
else
           
{
               path 
= AppDomain.CurrentDomain.BaseDirectory + "Bin\";
           }
这样如果我们写了一个类库,类库中用到了Assembly.LoadFrom,由于是通用类库,所以可能用到Windows程序中也可能用到Web中,那么用上面的代码就很方便了.
posted @ 2007-03-08 20:51  深蓝  阅读(1959)  评论(0编辑  收藏  举报

我要啦免费统计