0

I have a windows app that needs to work on all platforms of windows. I recently installed the Windows API Code Pack and replaced a folder browser with a "CommonOpenFileBrowser". This was great until I tried running my program on a windows XP machine where I got the exception:

PlatformNotSupportedException, CommonOpenFileDialog requires vista or later.

I would like to keep using the CommonOpenFileDialog for vista and above, but is it possible to revert to the old folder browser if it detects a windows XP operating system at run time?

More Thoughts:

I can detect my operating system by using :

// If Windows Vista or above
if (Environment.OSVersion.Version.Major >= 6)

But the exception occurs on start up, even before the CommonOpenFileDialog is shown. I have heard something about dynamically loading code but I have very little experience with this.

Takahashinator
  • 189
  • 1
  • 7

1 Answers1

0

So it turns out that I had the solution all along. All I had to do was:

 if (Environment.OSVersion.Version.Major >= 6)
 {
     var openCommonDialog = new CommonOpenFileDialog();
 }
 else 
 {
     var openFileDialog = new FolderBrowserDialog();
 }

The reason I was crashing at startup is that the CommonOpenFileDialog was instantiated in the designer.cs file. Once this was removed my fix worked.

Takahashinator
  • 189
  • 1
  • 7