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

Hakan
Hakan used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,

What platform are you referring to?

Author

Commented:
I wonder are there any general platform functions which has scope all Windows versions
Eduard GherguArchitect - Coder - Mentor

Commented:
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.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
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

Author

Commented:
Hi Éric,

Is there any support for WPF ?
Architect - Coder - Mentor
Commented:
Hi,
The WinForms OpenFileDialog is a wrapper over native Windows API calls. There is a such a wrapper in WPF, too, but the result is the same.
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Hakan,

OpenFileDialog will work across Windows versions (all currently supported versions of Desktop/Server editions) but it will not work on cross-platforms i.e. Linux, Mac etc.

Regards,
Chinmay.
Eduard GherguArchitect - Coder - Mentor

Commented:
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.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
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 GherguArchitect - Coder - Mentor

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial