?
Solved

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

Posted on 2014-04-25
5
Medium Priority
?
238 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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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