这是我的代码。
我可以在不物理保存服务器的情况下做到这一点吗?
谢谢!!
StringBuilder text = new StringBuilder();
string sFileName = "file.txt";
using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("docs\\" + sFileName), false, Encoding.ASCII))
{
SW.WriteLine("test");
SW.Close();
}
System.IO.FileStream fs = null;
fs = System.IO.File.Open(Server.MapPath("docs\\" + sFileName), System.IO.FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.AddHeader("Content-disposition", "attachment; filename=" + sFileName);
Response.ContentType = "text/plain";
Response.BinaryWrite(btFile);
Response.End();