<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>对于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中,那么用上面的代码就很方便了.
string
path
=
""
;
if
(System.Environment.CurrentDirectory
==
AppDomain.CurrentDomain.BaseDirectory)
//
Windows应用程序则相等

...
{
path=AppDomain.CurrentDomain.BaseDirectory;
}
else

...
{
path=AppDomain.CurrentDomain.BaseDirectory+"Bin\";
}
本文介绍了一种判断当前程序是Windows程序还是Web应用程序的方法。通过比较System.Environment.CurrentDirectory与AppDomain.CurrentDomain.BaseDirectory,可以确定程序类型并获取相应的路径。


被折叠的 条评论
为什么被折叠?



