

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a path to the desktop for current user in C#?
The desktop path of the current user can be fetched by using Environment.SpecialFolder. The Environment.SpecialFolder gets the path to the system special folder that is identified by the specified enumeration.
string desktopPath =
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
The System.Environment Class provides information about the current environment and platform. The System.Environment Class uses to retrieve Environment variable settings, Version of the common language runtime, contents of the call stack etc. This class cannot be inherited.
Environment class is static class which Provides the system configuration,Current program execution Environment as wel some properties for string manipulation such as news line,System Namespace represents the Environment Class.
Environment class is a combination of functions and Properties which represent the Environment variable details using IDictionary in the form of key,value pairs.
We can also loop through Dictionary to get all Environment variable details, before introducing all Environment variable, let us go through some frequently used Environment variable details. As Environment class is the static class because of this we directly access the methods and properties with help of class name itself without creating object.
Example
using System; namespace DemoApplication{ public class Program{ public static void Main(){ string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); Console.WriteLine($"Desktop Path: {desktopPath}"); Console.ReadLine(); } } }
Output
The output of the above code is
Desktop Path: C:\Users\UserName\Desktop
- Related Questions & Answers
- How to get current user is system user or not in android?
- How to remove connected remote desktop user sessions using PowerShell?
- How to get the protocol and page path of the current web page in JavaScript?
- How to get full path of current file's directory in Python?
- The simplest way to get the user's current location on Android
- How to get the current year in JavaScript?
- How to get the current date in Java?
- How to get connected remote desktop users on computers using PowerShell?
- The simplest way to get the user's current location on Android using Kotlin?
- How to get the current date to display in a Tkinter window?
- What is the best desktop configuration for a graphics designer?
- How to get the current URL with JavaScript?
- How to update User Logged in Time for a specific user in MySQL?
- How to get the only current year in JavaScript?
- How to Get the current language in Android device?