小弟目前初学,碰到个问题请大家帮忙看下。 下面那个方法是把数据以ms-execl的格式,以Response输出到浏览器(客户端),
怎么才能保存到服务器指定的目录中呢
public static void DataSetToExcel(DataSet ds)
{
DataTable dee = ds.Tables[0];
dee.DataSet.DataSetName = ds.ToString();
HttpContext.Current.Response.Clear();
System.IO.StringWriter sw = new System.IO.StringWriter(); //写数据,省略
...
...
... sw.Close();
string ls_FileName = "attachment; filename=";
ls_FileName += FileHelper.GetRandom();
ls_FileName += ".xls"; HttpContext.Current.Response.AddHeader("Content-Disposition", ls_FileName); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.Write(sw); HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
怎么才能保存到服务器指定的目录中呢
public static void DataSetToExcel(DataSet ds)
{
DataTable dee = ds.Tables[0];
dee.DataSet.DataSetName = ds.ToString();
HttpContext.Current.Response.Clear();
System.IO.StringWriter sw = new System.IO.StringWriter(); //写数据,省略
...
...
... sw.Close();
string ls_FileName = "attachment; filename=";
ls_FileName += FileHelper.GetRandom();
ls_FileName += ".xls"; HttpContext.Current.Response.AddHeader("Content-Disposition", ls_FileName); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.Write(sw); HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
解决方案 »
- 有没有什么办法防止别人猜测到后台地址?
- 问一个复杂的SQL语句,不是高手不要进哦!
- 簡體與繁體的問題﹐實在是想不明白
- 把原来的WEB控件全部放到用户控件上进行权限验证,我除去删除权限难道就是隐藏删除按钮这么简单?
- 求:固定表头、表格体滚动的DataGrid(要C#版)。
- 程序动态创建控件数组???高手来看看
- 用asp.net写一个远程ftp程序,请问哪里有这方面的资料或例子?
- 如何在windows xp professional上安装sqlserver 2000 enterprise?
- 打开虚拟路径下的数据库问题:Server.MapPath 出错
- 关于cookie的问题
- GridView的ButtonField和CommandField不可用
- asp.net中的 成员资格,角色管理,站点导航,个性化,健康监控web事件,web part个性化,配置文件保护 这些功能在实际开发中常用吗?
改成
System.IO;File.WriteAllText(Server.MapPath("~/xx/x.xls"),sw)
File.WriteAllText(HttpRuntime.AppDomainAppPath + "\\Temp\\123.xls", sw.ToString());
其中123.xls这个文件是每执行一次就会往里面写一次数据。如果多个用户同时操作那么不可能每次操作都能保存一次的吧 而是会覆盖原来的。这个问题我自己再想办法解决,晚点我再结贴了,还是谢谢你的帮助。