如何获取当前工作目录路径c#? [英] How to get current working directory path c#?

查看:21
本文介绍了如何获取当前工作目录路径c#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中有一个游标文件.我在代码中给出了绝对路径,即

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");

推荐答案

您可以使用静态 Directory 类 - 但是当前目录与原始目录不同,原始目录是进程所在的目录开始了.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆