C# WindowsForms File Dialog doesn't display the path of selected file


I need the path of the selected file from a file dialog in windows forms and for some reason, the complete path is empty string after the selection.


  openZipFileDialog.FileName = "apache-tomcat-6.0.44-windows-x64.zip";
            if (result == DialogResult.OK) // Test result.
                System.IO.FileInfo fInfo = new System.IO.FileInfo(openZipFileDialog.FileName);

                string strFileName = fInfo.Name;
                string path = Path.GetDirectoryName(openZipFileDialog.FileName); //empty string ?

                TomcatPath = strFileName + ", " + path;

Open in new window

Framework is .NET 4.0
LVL 12
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


in openZipFileDialog.FileName you give no Path information that's why the function doesn't work

for reference


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Where are you showing the dialog at?...is there some code missing?

Should be something like:
        string TomcatPath = "";

        private void button1_Click(object sender, EventArgs e)
            OpenFileDialog openZipFileDialog = new OpenFileDialog();
            openZipFileDialog.FileName = "apache-tomcat-6.0.44-windows-x64";
            openZipFileDialog.Filter = "Zip files (*.zip)|*.zip";
            DialogResult result = openZipFileDialog.ShowDialog();
            if (result == DialogResult.OK) 
                System.IO.FileInfo fInfo = new System.IO.FileInfo(openZipFileDialog.FileName);
                TomcatPath = String.Format("{0}, {1}", fInfo.Name, fInfo.DirectoryName);

                // ... do something with "TomcatPath" ...


Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.