C# Path Compression Issue
I'm having an issue with 开发者_开发问答path compression. I'm reading a registry value, such as %USERPROFILE%\AppData\Roaming. The problem I'm having is it keeps expanding the the path out to C:\Users\John\AppData\Roaming. I know about Environment Expand, but I don't want to use that in case I have an path compression issue in the future. The code I'm using is:
RegistryKey hkUsersPath = Registry.Users.OpenSubKey(@".DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\");
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("AppData"));
if (hkUsersPath.GetValue("AppData") == null)
DefaultAppData = Convert.ToString(hkUsersPath.GetValue("APPDATA"));
Any advice is welcome. Thank you.
There's an overloaded GetValue method that you can call where you can specify not to expand environment variables:
hkUsersPath.GetValue("AppData", null, RegistryValueOptions.DoNotExpandEnvironmentNames);
精彩评论