雨落星沉
生而有涯,学而无涯。
 1         /// <summary>
 2         /// 选择文件对话框
 3         /// </summary>
 4         public string OpenFile(string folderPath)
 5         {
 6             OpenFileDialog ofd = new OpenFileDialog();
 7             ofd.InitialDirectory = "C:\\";
 8             ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
 9             ofd.FilterIndex = 2;
10             ofd.RestoreDirectory = true;
11 
12             if (ofd.ShowDialog() == DialogResult.OK)
13             {
14                 return folderPath = ofd.FileName;
15             }
16             else
17                 return null;
18         }
Void

 

1                      string filePath = "";
2                      filePath = OpenFile(filePath);
3                      if (filePath == null)
4                          return;
5                      this.Path = System.IO.Path.GetDirectoryName(filePath);//文件路径X:\\XX\\XXX\\XXXX
6                      this.Name = filePath.Substring(filePath.LastIndexOf('\\') + 1, filePath.LastIndexOf('.') - (filePath.LastIndexOf('\\') + 1));//文件名XXXX
7                      //this.Name = filePath.Substring(filePath.LastIndexOf('\\') + 1);//文件后缀.XXXX
8                      this.Format = filePath.Substring(filePath.LastIndexOf('.') + 1, filePath.Length - filePath.LastIndexOf('.') - 1);//文件格式 .XXXX
Command

 

posted on 2020-03-17 16:33  雨落星沉  阅读(107)  评论(0)    收藏  举报