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 }
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
君子当如竹,立志坚,品行洁。
浙公网安备 33010602011771号