简体   繁体   中英

Windows API Code Pack features on windows xp machine

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM