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");
To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory. The command pwd stands for print working directory.
Alternatively referred to as the working directory or current working directory (CWD), the current directory is the directory or folder where you are currently working. The following sections contain some common use examples involving the current working directory. Windows current directory.
On Windows, you need to use the equivalent functionality provided by the Windows API, ie GetCurrentDirectory() , declared in windows. h .
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);
use Application.StartupPath returns path for the executable file that started the application.
string pathCur = Path.Combine(Application.StartupPath, @"..\..\r.cur"); Cursor = new Cursor(pathCur);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With