如何保存我在桌面上创建的txt文件?
这是代码:
void CreaTxtBtnClick(object sender,EventArgs e){ string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); filePath = filePath + @"\Error Log\"; TextWriter sw = new StreamWriter(@"Gara.txt"); int rowcount = dataGridView1.Rows.Count; for(int i = 0; i < rowcount - 1; i++){ sw.WriteLine( dataGridView1.Rows[i].Cells[0].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[1].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[2].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[3].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[4].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[5].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[6].Value.ToString() + '\t' + dataGridView1.Rows[i].Cells[7].Value.ToString() + '\t' ); } sw.Close(); MessageBox.Show("File txt creato correttamente"); }
我按照这些指示思考
Environment.GetFolderPath(Environment.SpecialFolder.Desktop); filePath = filePath + @"\Error Log\"; TextWriter sw = new StreamWriter(@"Gara.txt");
解决方法
原文地址:https://www.jb51.cc/csharp/92846.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。