å¨é¡µé¢æä¸ä¸ªsaveFileDialog1æ§ä»¶;
private void btnJgbc_Click(object sender, EventArgs e)
{
try
{
DataTable myDT = new DataTable();
myDT = GvtoDT(ref myGV);
WriteTxt(myDT);
MessageBox.Show("ä¿åæåï¼");
}
catch
{
MessageBox.Show("ä¿å失败ï¼");
}
}
private void WriteTxt(DataTable tb)
{
StreamWriter sr;
string report;
if (File.Exists(Application.StartupPath + "//MyFile3.txt")) //å¦ææ件åå¨,åå建File.AppendText对象
{
sr = File.AppendText(Application.StartupPath + "//MyFile3.txt");
report = "appended";
}
else //å¦ææ件ä¸åå¨,åå建File.CreateText对象
{
sr = File.CreateText(Application.StartupPath + "//MyFile3.txt");
report = "created";
}
StringBuilder sb = new StringBuilder();
sr.WriteLine("注æ°/t红1/t红2/t红3/t红4/t红5/t红6/tè1/tè2/r/n");
foreach (DataRow dr in tb.Rows)
{
sr.WriteLine(dr[0].ToString() + "/t" + dr[1].ToString() + "/t" + dr[2].ToString() + "/t" + dr[3].ToString() + "/t" + dr[4].ToString() + "/t" + dr[5].ToString() + "/t" + dr[6].ToString() + "/t" + dr[7].ToString() + "/r/n");
}
sr.Close();
if( saveFileDialog1.ShowDialog()==DialogResult.OK)
{
File.Copy(Application.StartupPath + "//MyFile3.txt", saveFileDialog1.FileName, true);
File.Delete(Application.StartupPath + "//MyFile3.txt");
}
}
温馨提示:答案为网友推荐,仅供参考