Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-25
5
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 2000 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 45

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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