Click here to Skip to main content
11,706,455 members (49,862 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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:42pm
Edited 10-Sep-12 22:44pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 11-Sep-12 5:02am
   
Thanks Kuthuparakkal, i should really pay attention to these background settings!
Kuthuparakkal at 11-Sep-12 5:17am
   
np :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
0 OriginalGriff 202
1 Sergey Alexandrovich Kryukov 135
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,190
1 Sergey Alexandrovich Kryukov 8,407
2 CPallini 5,189
3 Maciej Los 4,756
4 Mika Wendelius 3,686


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100