Quantcast
Viewing all articles
Browse latest Browse all 3458

Re: My solution to the OpenFileDialog problems (C#)

Hi Raul,

 

i've had the same Issue with Windows 8.1 and Windows 10 - (SAP stays in the foreground):

 

My Problem is solved by creating of a new empty Windows-Form witch is owner of the Folder- or FileBrowser-Dialog.

 

 

 

  public static string GetFolderPath()

        {

            string path = "";

            try

            {            

            

            

                Thread t = new Thread((ThreadStart)delegate

                {

                  

                    FolderBrowserDialog objDialog = new FolderBrowserDialog();

                    //FileDialog objDialog = new OpenFileDialog(); 

                    objDialog.Description = "Please select a Folder";

               

                    objDialog.SelectedPath = @"C:\"; // or any other path you want to start...

                  

                    objDialog.ShowNewFolderButton = true;

                    //create a Form for ownership (SAP-Window won't work)

                    Form g = new Form();

                    g.Width = 200;

                    g.Height = 200;

                    g.Activate();

                    g.BringToFront();

                    g.Visible = true;                

                    g.TopMost = true;

                    g.Focus();

                    DialogResult objResult = objDialog.ShowDialog(g);

                                 

                    Thread.Sleep(100);

                    if (objResult == DialogResult.OK)

                    {

                        path = objDialog.SelectedPath;

                    }

                }

                )

                {

                    IsBackground = false,

                    Priority = ThreadPriority.Highest

                };

                t.SetApartmentState(ApartmentState.STA);

                t.Start();

                while (!t.IsAlive) ;

                Thread.Sleep(1);

                t.Join();

            }

            catch (Exception ex)

            {

                //Exception handling...

                //Funktionen.WriteError(ex);            

            }

 

 

            return path;

 

 

        }


Viewing all articles
Browse latest Browse all 3458

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>