Solved

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

Posted on 2014-04-25
5
225 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now