您的位置:首页 > 其它

文件流的写入,把文件写入到当前项目中的一个文件夹里,以当前系统时间的年月命名

2012-11-22 13:40 483 查看
string datenow = DateTime.Now.ToString();//获取当前的系统时间
string psth =Server.MapPath( "/wenjian/" + DateTime.Now.ToString("yyyyMM") + ".csv");//将要写入的路径,当前的项目文件夹下
//string path=Server.MapPath("wenjian")+"\\"+DateTime.Now.ToString("yyyyMM")+".txt";
string xinphone = this.TextBox1.Text.ToString();
string name = this.TextBox2.Text.ToString();
string yinphone = this.TextBox3.Text.ToString();
string yinfakayinghang = this.TextBox4.Text.ToString();
string yindaokahao = this.TextBox5.Text.ToString();
string now = DateTime.Now.ToString("yyyyMM");//获取当前的系统时间的年月
FileStream fs = new FileStream(psth, FileMode.Append);//这是往哪个文件夹中写,APPend的意思就是看当前有无这个文件,如果有的话就打开往里追加,如果没有就新建一 个 这个文件
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(xinphone + "," + name + "," + yinphone + "," + yinfakayinghang + "," + yindaokahao + "," + datenow);

sw.Close();
fs.Close();
ClientScript.RegisterStartupScript(this.GetType(), "a", "<script>alert('提交成功')</script>");后台弹出提交成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐