Skip to content

Instantly share code, notes, and snippets.

@stryqx
Created May 1, 2022 10:42
Show Gist options
  • Select an option

  • Save stryqx/0957df6d5406de649c4fa6f02c7c2de2 to your computer and use it in GitHub Desktop.

Select an option

Save stryqx/0957df6d5406de649c4fa6f02c7c2de2 to your computer and use it in GitHub Desktop.
Server Core support for OpenFileDialog/SaveFileDialog - C# Snippet
// 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