如何将导出的gridview文件保存在具有显示数据和时间的文件名的特定路径中 [英] How to save the exported gridview file in a particular path having file name showing data and time
本文介绍了如何将导出的gridview文件保存在具有显示数据和时间的文件名的特定路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想将导出的文件保存在特定路径中,具体名称格式显示数据和时间
我尝试了什么:
Hi
I want to save the exported file in a particular path with Specific name format showing data and time
What I have tried:
protected void ExportToExcel(object sender, EventArgs e)
{
gvDetails.AllowPaging = false;
this.bind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Name.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvDetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
推荐答案
string fileName = "Name";
string dateFormat = "MMMddYYYY"; // the format which you want to display
string outPutFileName = string.Format("{0}_{1}.xls",fileName,DateTime.Now.ToString(dateFormat));
Response.AddHeader("content-disposition", "attachment; filename=" + outPutFileName);
这篇关于如何将导出的gridview文件保存在具有显示数据和时间的文件名的特定路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文