现在实现的可以把csv文件存到绝对路径下,但是想实现可以手动选择存储路径该怎么改呢?(例如点击按钮,弹出存储路径对话框,然后选择路径)
string delimiter = ","; string outputFilename = "Robot"; string fullFilename = Path.Combine("D:\11",outputFilename);//路径的选择 StreamWriter csvStreamWriter = new StreamWriter(fullFilename, false, System.Text.Encoding.UTF8); //output header data string strHeader = ""; for (int i = 0; i < dataGridView1.Columns.Count; i++) { strHeader += dataGridView1.Columns[i].HeaderText + delimiter; } csvStreamWriter.WriteLine(strHeader); //output rows data for (int j = 0; j < dataGridView1.Rows.Count; j++) { string strRowValue = ""; for (int k = 0; k < dataGridView1.Columns.Count; k++) { strRowValue += dataGridView1.Rows[j].Cells[k].Value + delimiter; } csvStreamWriter.WriteLine(strRowValue); } csvStreamWriter.Close();
解决方案
40
这次话不多说
System.Windows.Forms.SaveFileDialog
https://msdn.microsoft.com/zh-cn/library/system.windows.forms.savefiledialog(v=vs.100).aspx
System.Windows.Forms.SaveFileDialog
https://msdn.microsoft.com/zh-cn/library/system.windows.forms.savefiledialog(v=vs.100).aspx