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

            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>");后台弹出提交成功

原文地址:https://www.cnblogs.com/zcwry/p/2782535.html