Search code examples
c#functionsystemenvironment

.NET Core: C# Environment.GetFolderPath not defined


I was trying to search for a possibility to get the Desktopfolder of the current user in my consoleprogram. I found this one:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

Now VS brings up an failure that there is no definition for "GetFolderPath" in "Environment".

Maybe someone can help me out. Thanks!


Solution

  • Upgrade your project to using .net Core 2.0 (.net Standard 2.0). The function is available there, but not in earlier versions.

    Alternatively, you can use a normal .net console application project instead of a .net Core project, but that will not be platform independent.

    Note: Although .net Standard 2.0 supports System.Environment.GetFolderPathit might not provide a meaningful result for all possible parameter values on all platforms and even throw an Exception on some platforms for some parameter values.