Get The Path Of A File Using OpenFileDialog In C#

This snippet uses the OpenFileDialog class to get a files path.


  1. OpenFileDialog FD = new OpenFileDialog();
  2. string filenname = "";
  3. string path = "";
  4. if (FD.ShowDialog() == DialogResult.OK)
  5. {
  6.   filenname = System.IO.Path.GetFileName(FD.FileName);
  7.   path = System.IO.Path.GetDirectoryName(FD.FileName);
  8. }
  9. MessageBox.Show(filenname, "Filename");
  10. MessageBox.Show(path, "Directory");

No comments:

Post a Comment