c#获取dll物理路径的方法
2010-09-15 10:24
211 查看
在写类库项目时,经常会有某些特殊业务需要用到服务器端的物理路径,使用传统的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;
}
转自:http://www.aspdiy.net/article/webcode/41.htm
/// 获取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;
}
转自:http://www.aspdiy.net/article/webcode/41.htm
相关文章推荐
- c#调用dll获取dll物理路径的方法
- c#调用dll获取dll物理路径的方法
- C# 调用dll获取dll物理路径的方法
- C# 调用dll获取dll物理路径的方法
- asp.net C#网站项目 获取物理路径、虚拟路径的方法
- C#获取文件物理相对绝对路径目录的N种方法
- asp.net C#网站项目 获取物理路径、虚拟路径的方法
- asp.net C#网站项目 获取物理路径、虚拟路径的方法
- C#的dll被其他程序调用时,获取此dll正确的物理路径
- C#获取dll路径的方法(适合B/S和C/S架构)
- C#获取当前路径的方法集合
- “黑马程序员” C#中获取当前路径的几种方法
- 总结C#获取当前路径的7种方法
- C#获取项目程序及运行路径的方法
- C#中获取当前路径的几种方法
- C#获取项目程序路径的方法
- C#获取项目程序路径的方法
- C#获取项目程序路径的方法
- C#获取当前应用程序启动路径的方法
- c# 获取路径的几种方法