使用C#返回系統特殊路徑

來源:互聯網
上載者:User
using System;
using Microsoft.Win32;

namespace SystemPathsApp
{
/// <summary>
/// Summary description for SystemPaths.
/// </summary>
public class SystemPaths
{
public SystemPaths()
{
//
// TODO: Add constructor logic here
//
folders = OpenRegistryPath(Registry.CurrentUser,@"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders");
}

private RegistryKey folders;

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;
}

/// <summary>
/// </summary>
/// <param name="path">
/// Desktop 案頭目錄
/// Fonts 字型目錄
/// NetHood 網路位置
/// Personal 我的文件目錄
/// Programs 開始菜單程式目錄
/// Recent 存放使用者最近訪問檔案捷徑的目錄
/// SendTo 發送到目錄
/// StartMenu 開始菜單目錄
/// Startup 開始菜單啟動項目錄
/// Favorites 收藏夾目錄
/// History 網頁曆史目錄
/// Cookies cookies目錄
/// Cache 緩衝目錄
/// AppData 應用程式資料目錄
/// PrintHood 列印目錄
/// </param>
/// <returns></returns>
public string Customize(string path)
{
return folders.GetValue(path).ToString();
}

public string Desktop()
{
return Customize("Desktop");
}

public string Cookies()
{
return Customize("Cookies");
}

public string MyDocuments()
{
return Customize("Personal");

}

public string History()
{
return Customize("History");
}

public string Favorites()
{
return Customize("Favorites");
}

}
}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.