Solved

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

Posted on 2014-04-25
5
231 Views
Last Modified: 2014-04-25
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
0
Comment
Question by:stephenlecomptejr
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 40022835
put in fdPath.FileName = ""; under the fdPath.InitialDirectory like below
fdPath.InitialDirectory = defaultpath;
                
fdPath.FileName = "";

DialogResult result = this.fdPath.ShowDialog();

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40022840
fdPath.InitialDirectory = defaultpath;

What value does defaultpath have?
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 40022852
string defaultpath = txtPath.Text;


which never, ever has openFileDialog1....
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 40022860
Thank you dustock
0
 
LVL 9

Expert Comment

by:dustock
ID: 40022865
No problem
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question