提取SaveFileDialog的保存路径

 

 string localFilePath, fileName, newFileName, FilePath;

 SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 

saveFileDialog1.Title = "保存文本文档";

saveFileDialog1.Filter = " txt(*.txt)|*.txt|All files(*.*)|*.*";

 saveFileDialog1.FilterIndex = 1;  //设置默认文件类型显示顺序
 
if (saveFileDialog1.ShowDialog() == DialogResult.OK)

 { 
 
localFilePath = saveFileDialog1.FileName.ToString();//获得文件路径

fileName = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);   //获取文件名,不带路径

FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));//获取文件路径,不带文件名 

 newFileName = DateTime.Now.ToString("yyyymmdd") + fileName;   //给文件名前加上时间

saveFileDialog1.FileName.Insert(1,"abc");//在文件名里插入字符 
}

 

你可能感兴趣的:(c#)