Avatar of Skale
Skale
 asked on

What can i use when platform not supported for OpenFileDialog in C#

Hello I'm using below code to get for open file dialog but i'd like to know is there any solution to use different open file dialog can support platform.

So can anyone help me to complete catch section of below code?

   try
            {
                Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog dlg = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog
                {
                    ShowPlacesList = true,
                    Multiselect = false,
                    InitialDirectory = "",
                    IsFolderPicker = false,
                    AddToMostRecentlyUsedList = false,
                    EnsurePathExists = true,
                    EnsureFileExists = true,
                    EnsureValidNames = true,
                    Title = "Open Model"
                    //DefaultDirectory = ""
                    //EnsureReadOnly = false
                    //AllowNonFileSystemItems = false
            };

                dlg.Filters.Add(new Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogFilter("Text Files", "*.txt"));

                if (dlg.ShowDialog() == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
                {
                    return dlg.FileName;
                }
            }
            catch (System.PlatformNotSupportedException)
            {
                //TODO: Support will added for not supported platforms
            }

            return null;

Open in new window

C#

Avatar of undefined
Last Comment
Eduard Ghergu

8/22/2022 - Mon
Eduard Ghergu

Hi,

What platform are you referring to?
Skale

ASKER
I wonder are there any general platform functions which has scope all Windows versions
Eduard Ghergu

Hi,
The defined scope is too broad. There is not possible to support all Windows versions (16,32,64-bit, Mobile, ARM). You'll need to be more specific.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Éric Moreau

If you are using the built-in OpenFileDialog, it will run on any computer running Windows. Have a look at https://www.emoreau.com/Entries/Articles/2003/06/Common-Dialogs.aspx
Skale

ASKER
Hi Éric,

Is there any support for WPF ?
ASKER CERTIFIED SOLUTION
Eduard Ghergu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Chinmay Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Eduard Ghergu

Hi,
There is no direct support for UI development, cross-platform, in .NET. There are some alternative projects, but nothing native, to call it like this. However, you can have a look at Mono, instead. https://www.mono-project.com/docs/gui/
This project is under Microsoft's .NET umbrella, but there is some long road ahead till it will get fully integrated with the framework.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

which platforms are you targeting? Usually, your UI will be recreated for various platforms because the look is totally different. You can reuse the same business layer but with different UI.

Eduard, isn't Mono almost dead now that it has been converted to Xamarin (which is part of Visual Studio)? https://dotnet.microsoft.com/apps/xamarin
Eduard Ghergu

Hi,

Mono is not really dead as long as Xamarin was targeted for mobile platforms. In a couple of years probably it is going to be discontinued when .Net 5.0 will hit the market (the latest greatest that it's aiming to unify all the .Net versions and incarnations). In the end, probably they will favor WPF over other technologies, but we'll see.