C # obtain the path of a user's desktop and other special systems

Source: Internet
Author: User

Different operating systems have different desktop paths and different installation locations.
C # You can read the location of your special folders (desktops, favorites, etc.) from the Windows registry.
CodeAs follows:

Using Microsoft. win32; namespace jpgcompact {public partial class mainform: FORM {private void test () {registrykey folders; folders = openregistrypath (registry. currentuser, @ "\ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders"); // Windows user desktop path string export toppath = folders. getvalue ("desktop "). tostring (); // Windows user font directory path string fontspath = folders. getvalue ("fonts "). tostring (); // Windows user network neighbor path string nethoodpath = folders. getvalue ("nethood "). tostring (); // Windows user my document path string personalpath = folders. getvalue ("personal "). tostring (); // Windows user Start Menu Program Path string programspath = folders. getvalue ("programs "). tostring (); // For Windows users, the directory path string recentpath = folders. getvalue ("Recent "). tostring (); // The path string sendtopath = folders. getvalue ("sendto "). tostring (); // Windows user Start Menu directory path string startmenupath = folders. getvalue ("startmenu "). tostring (); // Windows user Start Menu startup Item directory path string startuppath = folders. getvalue ("Startup "). tostri Ng (); // Windows user favorites directory path string favoritespath = folders. getvalue ("favorites "). tostring (); // path of the historical Windows user webpage directory string historypath = folders. getvalue ("History "). tostring (); // Windows user cookies directory path string cookiespath = folders. getvalue ("cookies "). tostring (); // Windows user cache directory path string cachepath = folders. getvalue ("cache "). tostring (); // data directory path of the Windows user application string appdatapath = folders. getvalue (" Ppdata "). tostring (); // Windows user print directory path string printhoodpath = folders. getvalue ("printhood "). tostring ();} private registrykey openregistrypath (registrykey root, string s) {S = S. remove (0, 1) + @ "\"; while (S. indexof (@"\")! =-1) {root = root. opensubkey (S. substring (0, S. indexof (@ "\"); s = S. remove (0, S. indexof (@ "\") + 1);} return root ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.