Click here to Skip to main content
Sign Up to vote bad
good
See more: C#Bug
Hi all,
 
The problem im having involves the ProgramFiles and ProgramFiles(x86).
 
I don't know if this is just a problem with my machine being Windows 8 or it being 64bit but the following both resolve to "C:\Program Files (x86)":
 
string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string progfilesx86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
 
Using other sources i can see other people have had this problem but is there any way around it that anyone knows?
Thanks!
Posted 10 Sep '12 - 22:42
Edited 10 Sep '12 - 22:44


2 solutions

it depends on the Target platform of your app.. If you set it x64 build, and you run it on x64 machine you should get Program Files. On the other hand if it's x86 target platform then you get C:\Program Files (x86) even if you execute it on x64 machine
  Permalink  
Comments
MitchG92_24 - 11 Sep '12 - 5:02
Thanks Kuthuparakkal, i should really pay attention to these background settings!
Kuthuparakkal - 11 Sep '12 - 5:17
np :)
There is a quick fix to this programmatically:
 
string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
if (progfiles.EndsWith("(x86)"))
{
    progfiles = progfiles.Replace(" (x86)", "");
}
string progfilesx86 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 325
1 Sergey Alexandrovich Kryukov 140
2 Mohammed Hameed 123
3 Santhosh G_ 113
4 Ron Beyer 99
0 Sergey Alexandrovich Kryukov 8,286
1 OriginalGriff 6,561
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid