Link to home
Create AccountLog in
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

Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Hi,

What platform are you referring to?
Avatar of Skale
Skale

ASKER

I wonder are there any general platform functions which has scope all Windows versions
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.
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
Avatar of Skale

ASKER

Hi Éric,

Is there any support for WPF ?
ASKER CERTIFIED SOLUTION
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.
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
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.