請參閱How to get the path to CSIDL_COMMON_DOCUMENTS in .NET 3.5?
它const int CSIDL_COMMON_DOCUMENTS = 0x002e;
提供的位置。
對於Fonts
文件夾,使用const int CSIDL_FONTS = 0x0014;
這將是:
[DllImport("shell32.dll"), CharSet = CharSet.Auto]
static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, uint dwFlags, [Out] StringBuilder pszPath);
const int CSIDL_FONTS = 0x0014;
const int CSIDL_FLAG_CREATE = 0x8000;
StringBuilder sb = new StringBuilder();
int retVal = SHGetFolderPath(IntPtr.Zero,
CSIDL_FONTS | CSIDL_FLAG_CREATE,
IntPtr.Zero,
0,
sb);
Debug.Assert(retVal >= 0); // assert that the function call succeeded
String folderLocation = sb.ToString();
我看不出爲什麼這不會在3.5工作...什麼錯誤信息你好嗎? – andypaxo
@andypaxo我已更新錯誤消息 – Anuya