以txt文件为例
打开文件选择框
private void btn_choose_Click(object sender, EventArgs e) { OpenFileDialog** InvokeDialog = new OpenFileDialog(); InvokeDialog.Filter = "txt文件|*.txt"; if (InvokeDialog.ShowDialog() == DialogResult.OK) { this.txt_path.Text = InvokeDialog.FileName; filepath = this.txt_path.Text; } }
另存文件
private void btn_selRoute_Click(object sender, EventArgs e) { string localFilePath = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter= "txt文件(*.txt)|*.txt"; sfd.FilterIndex= 1; sfd.RestoreDirectory= true; if (sfd.ShowDialog() == DialogResult.OK) { localFilePath = sfd.FileName.ToString(); string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); this.txt_saveRoute.Text = localFilePath; } }