Ore*_*ost 8 .net windows windows-shell
我需要将文件存储到Windows上的公共桌面.该应用程序是一个非常特殊的应用程序,适用于一个特殊的PC(设备准备),因此非技术用户必须很容易找到并修改配置文件.现在我们切换到一个域,因为不同的人(具有不同的帐户)应该使用该软件,它必须在一个共同的位置,每个用户都可以看到.所以请不要问为什么它在桌面上;)
以前,我刚刚用过Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
.SpecialFolder
枚举中有几个常见文件夹,但普通桌面似乎不存在.难道我失去了一些东西,或者我要的P/Invoke SHGetSpecialFolderPath
用CSIDL_COMMON_DESKTOPDIRECTORY
?
我认为您必须使用SHGetSpecialFolderPath
API,因为“CommonDesktopDirectory”没有枚举值。您不能显式使用 的值CSIDL_COMMON_DESKTOPDIRECTORY
并将其转换为Environment.SpecialFolder
,因为该GetFolderPath
方法会检查该值是否在枚举中定义。这是该方法的代码GetFolderPath
(来自 Reflector):
public static string GetFolderPath(SpecialFolder folder)
{
if (!Enum.IsDefined(typeof(SpecialFolder), folder))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GetResourceString("Arg_EnumIllegalVal"), new object[] { (int) folder }));
}
StringBuilder lpszPath = new StringBuilder(260);
Win32Native.SHGetFolderPath(IntPtr.Zero, (int) folder, IntPtr.Zero, 0, lpszPath);
string path = lpszPath.ToString();
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
return path;
}
Run Code Online (Sandbox Code Playgroud)
因此您可以轻松复制和调整您需要的部分......
归档时间: |
|
查看次数: |
2324 次 |
最近记录: |