2010年1月20日 星期三

[C#] Listbox 存至 CSV

private void button2_Click(object sender, EventArgs e)
{
//弄存檔檔名
saveFileDialog1.ShowDialog();
string save_path = saveFileDialog1.FileName + ".CSV";
int aa = listBox3.Items.Count;
//Save
System.IO.StreamWriter fn = new System.IO.StreamWriter(save_path);
for (int i = 0; i < aa; i++)
{
fn.WriteLine(listBox3.Items[i].ToString().Replace("=", ","));
}
fn.Flush();
fn.Close();
MessageBox.Show("存檔成功 ^^=");
}

沒有留言:

張貼留言