Created
May 1, 2022 10:42
-
-
Save stryqx/0957df6d5406de649c4fa6f02c7c2de2 to your computer and use it in GitHub Desktop.
Server Core support for OpenFileDialog/SaveFileDialog - C# Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Code based on the code provided by @kpreisser here - https://github.com/microsoft/dotnet-framework-early-access/issues/23#issuecomment-393134611 | |
| // Add COMException support | |
| using System.Runtime.InteropServices; | |
| // Upgrade any of the following: | |
| // if (xxx.ShowDialog() == DialogResult.OK) | |
| // to use the following instead: | |
| System.Windows.Forms.DialogResult result; | |
| try | |
| { | |
| result = xxx.ShowDialog(); | |
| } | |
| catch (COMException) when (xxx.AutoUpgradeEnabled) | |
| { | |
| xxx.AutoUpgradeEnabled = false; | |
| try | |
| { | |
| result = xxx.ShowDialog(); | |
| } | |
| finally | |
| { | |
| xxx.AutoUpgradeEnabled = true; | |
| } | |
| } | |
| if (result == DialogResult.OK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment