编写控件的时候是生成.dll的文件,用Application.StartupPath;获取路径为d:\Program Files\Microsoft Visual Studio 8\Common7\IDE而不是平常项目的目录。用Directory.GetCurrentDirectory();获取当前的工作的目录,结果却是d:\data是我操作数据的目录。怎样才能获取的到生成.dll文件的目录路径呢?!
调试欢乐多
这个就是你编译好的dll文件路径
解决办法,因为这个dll是给自己用,Application.StartupPath,Directory.GetCurrentDirectory()而这两个获取路径的方法是在设计时,获得的路径不是我们要的,在我们运行我们的程序时是对的.
所以我就做了一个判断,如果在运行时就从xml文件里取连接字符串.如果不是,就读程序里写死的那个
msn:[email protected]
string path = myAssembly.Location;
/**//// <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;
}