To get the Solution Path

This is a much common question.

Even though many of you guys know about getting the the current execution path, am just sharing that code.

private static string CurrentAssemblyDirectory
        {
            get
            {
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                path = Path.GetDirectoryName(path);
                path = path.Replace("\\RegressionSuit\\bin\\Release", ""); // Change it to the folder that you want. 
                return path;
            }
        }

CodeBase which gives you the path in URI format, then UriBuild.UnescapeDataString removes the File:// at the beginning, and GetDirectoryName changes it to the normal windows format.

Leave a Reply

Your email address will not be published. Required fields are marked *