c#有关获取系统路径
来源:互联网 发布:金额均分算法 编辑:程序博客网 时间:2024/06/06 18:56
一、
系统路径可以通过
Enviroment.SystemDirectory获得
中间的参数为Environment.SpecialFolder.DesktopDirectory,这样获得桌面目录
返回“我的文档”路径字符串
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
二、
不同的操作系统,桌面的路径不尽相同,而且随着用户安装位置的不同也不同。
C#可以从Windows注册表读取得到用户的特殊文件夹(桌面、收藏夹等等)的位置。
代码如下:
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用户桌面路径 string desktopPath = folders.GetValue("Desktop").ToString(); // Windows用户字体目录路径 string fontsPath = folders.GetValue("Fonts").ToString(); // Windows用户网络邻居路径 string nethoodPath = folders.GetValue("Nethood").ToString(); // Windows用户我的文档路径 string personalPath = folders.GetValue("Personal").ToString(); // Windows用户开始菜单程序路径 string programsPath = folders.GetValue("Programs").ToString(); // Windows用户存放用户最近访问文档快捷方式的目录路径 string recentPath = folders.GetValue("Recent").ToString(); // Windows用户发送到目录路径 string sendtoPath = folders.GetValue("Sendto").ToString(); // Windows用户开始菜单目录路径 string startmenuPath = folders.GetValue("Startmenu").ToString(); // Windows用户开始菜单启动项目录路径 string startupPath = folders.GetValue("Startup").ToString(); // Windows用户收藏夹目录路径 string favoritesPath = folders.GetValue("Favorites").ToString(); // Windows用户网页历史目录路径 string historyPath = folders.GetValue("History").ToString(); // Windows用户Cookies目录路径 string cookiesPath = folders.GetValue("Cookies").ToString(); // Windows用户Cache目录路径 string cachePath = folders.GetValue("Cache").ToString(); // Windows用户应用程式数据目录路径 string appdataPath = folders.GetValue("Appdata").ToString(); // Windows用户打印目录路径 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; } }}
http://apps.hi.baidu.com/share/detail/37823127
- c#有关获取系统路径
- C# 如何获取有关路径
- C#获取特殊系统路径
- C#获取特殊系统路径
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- 用C#获取系统有关环境、属性
- C#中获取我的文档系统文件夹路径
- 获取当前系统桌面路径(C# 代码)
- 获取当前系统桌面路径(C# 代码)
- C#获取系统的特殊文件夹路径
- C#获取当前系统桌面路径
- 获取当前系统桌面路径(C# 代码)
- 如果利用C#获取系统有关环境和属性
- java学习笔记(二十六)多态性
- c#写入文件读出文件
- C#最小二乘法直线拟合算法
- java学习笔记(二十七)抽象类与设计模式
- C语言点滴
- c#有关获取系统路径
- 一些杂类网站
- 函数名与函数指针解惑
- java学习笔记(三十四)认识Runtime类
- C语言复杂声明
- VUSB(原AVRUSB)笔记1------电路图分析
- java 基TCP的多线程 网络编程
- 感冒也来凑热闹!感冒而有感!
- 两款PHP环境搭建工具