- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- 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 name of the current executable in C#?
- How to Get the Path of a Linux Command?
- How to get all the directories and sub directories inside a path in C#?
- How to get connected remote desktop users on computers using PowerShell?
- How to get current time and date in C++?
- How to get Input from the User in Golang?
- Get the HashCode for the current UInt64 instance in C#
- Get the HashCode for the current UInt32 instance in C#
- Shortest Path to Get All Keys in C++
- The simplest way to get the user's current location on Android using Kotlin?
