示例情景:
你通过代码在服务器的内存里生成了一个CSV文件,并且希望用户下载时出现的另存为对话框中的默认文件名为"Stocks-2007-03-12.csv":
string filename="Stocks-2007-03-12.csv"; string fileContent="..."; Response.ClearHeaders(); Response.ClearContent(); Response.HeaderEncoding = Encoding.Default; Response.ContentEncoding = Encoding.Default; Response.AddHeader("Content-Disposition", "attachment; filename="+filename); Response.Write(fileContent); Response.Flush(); Response.End();