Environment.GetFolderPath(... CommonApplicationData)仍返回" C:\ Documents和Settings \"在Vista [英] Environment.GetFolderPath(...CommonApplicationData) is still returning "C:\Documents and Settings\" on Vista

查看:588
本文介绍了Environment.GetFolderPath(... CommonApplicationData)仍返回" C:\ Documents和Settings \"在Vista的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,你应该让你拥有独立于操作系统的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 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 像它应该...任何想法

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 Data SpecialFolder.CommonApplicationData: C:\Documents and Settings\All Users\Application Data SpecialFolder.ProgramFiles: C:\Program Files SpecialFolder.CommonProgramFiles: C:\Program Files\Common Files SpecialFolder.DesktopDirectory: C:\Documents and Settings\blake\Desktop SpecialFolder.LocalApplicationData: C:\Documents and Settings\blake\Local Settings\Application Data SpecialFolder.MyDocuments: C:\Documents and Settings\blake\My Documents SpecialFolder.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆