如何保存由我在桌面上创建的txt文件?C#在桌面上保存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");
我可以节省桌面上的文件,但TXT在错误的道路正确创建。 我该如何解决它?
它保存在哪里? – active92
在程序文件夹中 – Matteo