asp.net c#调用dll获取dll物理路径的方法
作者:98tj 日期:2008-06-22
在写类库项目时,经常会有某些特殊业务需要用到服务器端的物理路径,使用传统的System.IO.Directory.GetCurrentDirectory()方法返回的则是WINNT\System32目录,这个一般不能满足正常的业务需求,而要得到具体运行DLL所在的物理目录可以通过Assembly.GetExecutingAssembly().CodeBase属性来取得,具体参考方法如下
复制内容到剪贴板
程序代码
程序代码 /**//// <summary>
/// 获取Assembly的运行路径
/// </summary>
/// <returns></returns>
private string GetAssemblyPath()
{
string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;
_CodeBase = _CodeBase.Substring(8,_CodeBase.Length - 8); // 8是 file:// 的长度
string[] arrSection = _CodeBase.Split(new char[]{'/'});
string _FolderPath = "";
for(int i=0;i<arrSection.Length-1;i++)
{
_FolderPath += arrSection[i] + "/";
}
return _FolderPath;
}
/// 获取Assembly的运行路径
/// </summary>
/// <returns></returns>
private string GetAssemblyPath()
{
string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;
_CodeBase = _CodeBase.Substring(8,_CodeBase.Length - 8); // 8是 file:// 的长度
string[] arrSection = _CodeBase.Split(new char[]{'/'});
string _FolderPath = "";
for(int i=0;i<arrSection.Length-1;i++)
{
_FolderPath += arrSection[i] + "/";
}
return _FolderPath;
}
评论: 1 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志:
回复
]