string path = Path.GetDirectoryName(
Assembly.GetAssembly(typeof(MyClass)).CodeBase);
Run Code Online (Sandbox Code Playgroud)
输出:
文件:\ d:\学习\ CS \测试\的test.xml
返回d:\ learning\cs\test\test.xml的最佳方法是什么
file:\\doc.Save(returnPath)但是doc.Load(returnPath),当我打电话时会抛出异常; 效果很好.谢谢.
Mat*_*hen 56
string path = new Uri(Assembly.GetAssembly(typeof(MyClass)).CodeBase).LocalPath;
Run Code Online (Sandbox Code Playgroud)
Chr*_*ich 16
如果需要该类程序集的目录,可以使用该Assembly.Location属性:
string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MyClass)).Location);
Run Code Online (Sandbox Code Playgroud)
但这与CodeBase财产并不完全相同.它Location是"包含清单的加载文件的路径或UNC位置",而" CodeBase是最初指定的程序集的位置,例如,在AssemblyName对象中".
System.Uri uri = new System.Uri(Assembly.GetAssembly(typeof(MyClass)).CodeBase);
string path = Path.GetDirectoryName(uri.LocalPath);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13975 次 |
| 最近记录: |