如何指定默认路径是桌面,不管是xp还是win7 记得,xp与win7的桌面路径是不一样的那么在设置 导出的文件默认到最终用户的桌面的时候,该如何写表示 默认到用户的桌面? 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop 利用环境变量进行统一windows安装的路径在环境变量里可以取到 %windir 也可以利用注册表获取不同的操作系统,桌面的路径不尽相同,而且随着用户安装位置的不同也不同。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; } }} 考考你是否真的了解构造函数 CS项目在一个form中按回车执行一butten点击事件 关于线程的问题 未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中。 C#中的光标问题 高手请解Visual Studio .net 问题... 字体变为乱码了?! asp.net的牛人请进 关于 OWC AxSpreadsheet的问题,请用过的过来帮看一下。谢谢 请问如何使vs.net编译"win32"平台的应用程序. C#的参数问题 求助一个正则表达式
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;
}
}
}