SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*";
sfd.FileName = "板材清单" + DateTime.Now.ToShortDateString().Replace(‘/‘, ‘-‘);
sfd.FileOk += Sfd_FileOk;//注册保存按钮的点击事件
sfd.ShowDialog();
string filePath = (sender as SaveFileDialog).FileName;
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using (File.Create(filePath))
{
}
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write))
using (StreamWriter sr = new StreamWriter(fs))
{
string plateList = HandleStockLoadingData.getInstance().GetAlreadyChoosePlateList();
string[] str = plateList.Split(‘;‘);
for (int i = 0; i < str.Length; i++)
{
sr.WriteLine(str[i]);
}
}
原文地址:https://www.cnblogs.com/wosshiakuan/p/9838169.html