Link to home
Start Free TrialLog in
Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America

asked on

openFileDialog1 pops up when I try to browse for a file using C# FileDialog

All,

Please note with the following code that for some reason puts openFileDialog1 as the filename - so if someone were to click Open it tries to say the name they are selecting is openFileDialog1.  I find that to be annoying - is there anything in the following code that I'm using incorrectly in the syntax causing this?

Please note result in attachment!

if (rbSingle.Checked == true)
            {
                string defaultpath = txtPath.Text;
                string newfile = "";



                fdPath.InitialDirectory = defaultpath;
                DialogResult result = this.fdPath.ShowDialog();
                if (result == DialogResult.OK)
                {
                    newfile = fdPath.FileName;

                    if (newfile != "openFileDialog1")
                            {
                                ShowMyMessageBox(@"File must be a PDF");
                            }

                    if (newfile.Substring(0, 1) != "C")
                    {
                        ShowMyMessageBox(@"File must be located locally on your C:\drive");
                    }
                    else
                    {
                        //fileName.Substring(fileName.Length - 4)
                        if (newfile.Substring(newfile.Length - 4) != ".pdf")
                        {
                            
                            
                        }
                        else
                        {
                            txtPath.Text = newfile;
                            this.Height = 516;
                        }

                    }

                }

            }

Open in new window

openFileDialog1.PNG
ASKER CERTIFIED SOLUTION
Avatar of dustock
dustock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndyAinscow
fdPath.InitialDirectory = defaultpath;

What value does defaultpath have?
Avatar of stephenlecomptejr

ASKER

string defaultpath = txtPath.Text;


which never, ever has openFileDialog1....
Thank you dustock
No problem