c# get the filename and pathname of the selected file of the dialog

system.window.form.openfiledialog OpenFileDialog;

openFileDialog=new OpenFileDialog();

openFileDialog.Title="Open file";

if (openFileDialog.ShowDialog() == DialogResult.OK)
      {
          string file = openFileDialog.FileName; (get the entire file name)
          string fileOpenPath, fileName;
          int index = file.LastIndexOf("\\"); (get the first starts with a position ending with "\\")

          fileOpenPath =file.Substring(0,index); (cut from 0 to the length of "\\")

fileName = file.Substring(index+1,file.Length-index-1); (plus one from index to total length)


}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325878107&siteId=291194637