Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I hide MVVM menu items in WPF/XAML? 1 36
How to use spatial data types in SQL Server Database project 2 43
parse string in c# 5 29
c#, case, if 4 19
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still 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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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