问题描述
据我了解,你应该让你拥有独立于操作系统的code使用 Environment.GetFolderPath
方法...
As I understand it, you're supposed to use the Environment.GetFolderPath
method so you have OS independent code...
Windows XP使用 C:\的Documents and Settings \
。 Windows Vista中使用 C:\ ProgramData code>和
C:\用户
Windows XP uses C:\Documents and Settings\
. Windows Vista uses C:\ProgramData
and C:\Users
.
我使用的是低于Windows Vista的计算机上的code和它返回一个 C:\的Documents and Settings \
目录中,而不是?C:\ ProgramData code>像它应该...任何想法
I'm using the code below on a Windows Vista computer and it's returning a C:\Documents and Settings\
directory instead of C:\ProgramData
like it should... Any ideas?
string commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
try
{
File.CreateText(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
"\\mycompany\\uid");
log.Debug("Created file successfully");
}
catch (Exception ex)
{
log.Error("Unable to create the uid file: ", ex);
}
推荐答案
我的安装程序拷贝已被XP的计算机上产生的log.txt文件。我一直在寻找在该日志文件认为它是在Vista上产生的。有一次,我定我的log4net的配置是兼容Vista。 Environment.GetFolderPath返航了预期的效果。因此,我关闭这个职位。
下面SpecialFolder路径引用可能是有用的:
My installer copied a log.txt file which had been generated on an XP computer. I was looking at that log file thinking it was generated on Vista. Once I fixed my log4net configuration to be "Vista Compatible". Environment.GetFolderPath was returning the expected results. Therefore, I'm closing this post.
输出在Windows Server 2003:
The following SpecialFolder path reference might be useful:
Output On Windows Server 2003:
输出在Vista上:
SpecialFolder.ApplicationData: C:\Documents and Settings\blake\Application DataSpecialFolder.CommonApplicationData: C:\Documents and Settings\All Users\Application DataSpecialFolder.ProgramFiles: C:\Program FilesSpecialFolder.CommonProgramFiles: C:\Program Files\Common FilesSpecialFolder.DesktopDirectory: C:\Documents and Settings\blake\DesktopSpecialFolder.LocalApplicationData: C:\Documents and Settings\blake\Local Settings\Application DataSpecialFolder.MyDocuments: C:\Documents and Settings\blake\My DocumentsSpecialFolder.System: C:\WINDOWS\system32`
SpecialFolder.ApplicationData: C:\Users\blake\AppData\Roaming
SpecialFolder.CommonApplicationData: C:\ProgramData
SpecialFolder.ProgramFiles: C:\Program Files
SpecialFolder.CommonProgramFiles: C:\Program Files\Common Files
SpecialFolder.DesktopDirectory: C:\Users\blake\Desktop
SpecialFolder.LocalApplicationData: C:\Users\blake\AppData\Local
SpecialFolder.MyDocuments: C:\Users\blake\Documents
SpecialFolder.System: C:\Windows\system32
这篇关于Environment.GetFolderPath(... CommonApplicationData)仍返回" C:\ Documents和Settings \"在Vista的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!