4
在Vista上,Environment.GetFolderPath(…CommonApplicationData)仍返回“ C:\ Documents and Settings \”
据我了解,您应该使用该Environment.GetFolderPath方法,以便拥有独立于操作系统的代码... Windows XP使用C:\Documents and Settings\。Windows Vista使用C:\ProgramData和C:\Users。 我在Windows Vista计算机上使用下面的代码,它返回的是C:\Documents and Settings\目录,而不是C:\ProgramData应有的目录。 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); }