Getting a path to the current solution in C# can be difficult because the idea of a Visual Studio solution is abstracted away from the actual code that is running. But not all is lost -- Visual Studio builds it's binaries into the same location unless you specify them otherwise, and we can use this to our advantage. For instance, if you have some project ExampleProject, obtaining the current path while running the code would result in this:
[solution path]\ExampleProject\bin\debug\
So to get the solution path, we simple need the following code:
1 2 3 4 5 6 |
using System.Reflection string cwd = System.Reflection.Assembly.GetExecutingAssembly().Location string projectName = "ExampleProject" //YOUR PROJECT NAME HERE string solutionPath = cwd.Replace(projectName + "\\bin\\Debug", ""); |
This code should return the solution path that the binaries are running in. Getting the solution path is typically not recommended for a variety of reasons, but can be useful for debugging and logging, or if you have no intention to publish your app.





