如何获得当前工作目录的路径C#? [英] How to get current working directory path c#?
问题描述
我在项目中的光标文件。我已在$ C $的绝对路径C即
F:/r.cur
问题是,这是硬codeD路径,我想相对路径,这样,如果我将我的解决方案到另一个系统的code应该不会影响。
请建议如何设置相对路径
//当前code我使用
p.Cursor =新的光标(F:/r.cur);
您可以使用静态目录
类的 - 但是当前目录是从原来的目录,这是不同的一个来自该进程启动。
System.IO.Directory.GetCurrentDirectory();
所以,你可以使用以下方法来获取应用程序的可执行文件的目录路径:
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
I have a cursor file in project. I have given the absolute path in code i.e
F:/r.cur
the problem is this is hard-coded path And i Want relative path so that if i move my solution to another system the code should not effect.
please suggest how to set relative path
//current code i am using
p.Cursor = new Cursor("F:/r.cur");
You can use static Directory
class - however current directory is distinct from the original directory, which is the one from which the process was started.
System.IO.Directory.GetCurrentDirectory();
So you can use the following to get the directory path of the application executable:
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
这篇关于如何获得当前工作目录的路径C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!