C#/WPF

[WPF] Get Solution Directory

딸기우유중독 2024. 10. 17. 15:45

 

 

 

public static class VisualStudioProvider
{
    public static DirectoryInfo TryGetSolutionDirectoryInfo(string currentPath = null)
    {
        var directory = new DirectoryInfo(
            currentPath ?? Directory.GetCurrentDirectory());
        while (directory != null && !directory.GetFiles("*.sln").Any())
        {
            directory = directory.Parent;
        }
        return directory;
    }
}

 

 

// get directory
var directory = VisualStudioProvider.TryGetSolutionDirectoryInfo();

 

 


 

 

https://stackoverflow.com/questions/19001423/getting-path-to-the-parent-folder-of-the-solution-file-using-c-sharp

 

Getting path to the parent folder of the solution file using C#

I am a beginner in C#, and I have a folder from which I am reading a file. I want to read a file which is located at the parent folder of the solution file. How do I do this? string path = "";

stackoverflow.com

 

 

 

728x90