You should not use Directory.GetCurrentDirectory()
in your case, as the current directory may differ from the execution folder, especially when you execute the program through a shortcut.
It’s better to use Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
for your purpose. This returns the pathname where the currently executing assembly resides.
While my suggested approach allows you to differentiate between the executing assembly, the entry assembly or any other loaded assembly, as Soner Gönül said in his answer,
System.IO.Path.GetDirectoryName(Application.ExecutablePath);
may also be sufficient. This would be equal to
System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Related Posts:
- Access to the path is denied
- Invalid URI: The format of the URI could not be determined
- How to open a new form from another form
- c# Show Windows Form
- Which passwordchar shows a black dot (•) in a winforms textbox?
- How do I fix a .NET windows application crashing at startup with Exception code: 0xE0434352?
- Playing a MP3 file in a WinForm application
- Unrecognized escape sequence for path string containing backslashes
- .Net 4.8 Support for Windows 10 ends in 26 days?
- What is a NullReferenceException, and how do I fix it?
- How do I get a random YouTube video with the YouTube API?
- An existing connection was forcibly closed by the remote host
- How can I convert String to Int?
- What is a NullReferenceException, and how do I fix it?
- I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- No connection could be made because the target machine actively refused it?
- What does a lock statement do under the hood?
- Could not load file or assembly or one of its dependencies
- Priority queue in .Net
- What is the difference between int, Int16, Int32 and Int64?
- What is the purpose of nameof?
- How to open .dll files to see what is written inside?
- Windows .NET API / Windows 7 / Bluetooth communication with Intel Curie Arduino / Genuino 101
- Error 1053 the service did not respond to the start or control request in a timely fashion
- foreach vs someList.ForEach(){}
- System.web.mvc missing
- Nullable object must have a value?
- Extension methods must be defined in a non-generic static class
- Metadata file ‘.dll’ could not be found
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- Add new item in existing array in c#.net
- How to resolve this System.IO.FileNotFoundException
- What is clr.dll on .Net framework and what does it do?
- Associating enums with strings in C#
- How do I declare a DefaultValue attribute whose value is an array of strings?
- How to resolve this System.IO.FileNotFoundException
- HttpWebRequest-The remote server returned an error: (400) Bad Request
- Extension methods must be defined in a non-generic static class
- Can’t use System.Windows.Forms
- How to use the “Using” statement in ASP.net razor webpages?
- How can I get the application’s path in a .NET console application?
- Reading settings from app.config or web.config in .NET
- How do I create a Shared Code project (.shproj)
- Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- Could not establish trust relationship for SSL/TLS secure channel — SOAP
- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
- How to add comments into a Xaml file in WPF?
- Why did I get the compile error “Use of unassigned local variable”?
- Reading CSV file and storing values into an array
- The remote server returned an error: (407) Proxy Authentication Required
- Merge two (or more) lists into one, in C# .NET
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- How do I restart my C# WinForm Application?
- .NET graph library around?
- How to split() a delimited string to a List
- Remove element of a regular array
- Best way to reverse a string
- An object reference is required to access a non-static member
- Task vs Thread differences
- How can I know if a process is running?
- XmlSerializer – There was an error reflecting type
- Run Command Prompt Commands
- windows could not start service on local computer error 5 access is denied
- Visual Studio keeps crashing
- How to add a new row to datagridview programmatically
- How can I implement static methods on an interface?
- Catch multiple exceptions at once?
- How do I exit a WPF application programmatically?
- How to convert UTF-8 byte[] to string
- .NET String.Format() to add commas in thousands place for a number
- Produce a random number in a range using C#
- How do I concatenate two arrays in C#?
- How to play a sound in C#, .NET
- What is a quick way to force CRLF in C# / .NET?
- How to resolve file being used by another process?
- How to enable assembly bind failure logging (Fusion) in .NET
- How to make inline functions in C#
- How to properly make a http web GET request
- Strip double quotes from a string in .NET
- c# .net change label text
- How to create a new object instance from a Type
- How to avoid a System.Runtime.InteropServices.COMException?
- Using FolderBrowserDialog in WPF application
- Is there an equivalent to the C# “var” keyword in C++/CLI?
- When should I use a List vs a LinkedList
- How can I generate random alphanumeric strings?
- How do you do a deep copy of an object in .NET?
- Get single listView SelectedItem
- .NET Core vs Mono
- Iif equivalent in C#
- LINQ query on a DataTable
- Best way to randomize an array with .NET
- Encrypt and decrypt a string in C#?
- Add item to Listview control
- Memory Leak caused by System.Drawing.Internal.GPStream
- Linq: GroupBy, Sum and Count
- How to enumerate an enum