你是通过客户端访问EXCEL文件的吧?
这肯定是不行的!
我是这样做的:
先上传该文件到服务器的一个目录下:
using System.IO;
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile = files[0];
string configPath = Server.MapPath("../../Config/");//得到上传目录
System.IO.File.Delete(configPath + name);//如果上次的文件还存在,先删除文件
postedFile.SaveAs(configPath + name);
然后再读取服务器上的文件。
你的可以这样:
//先在服务器上插入所有数据:
//然后提示客户端下载:
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(file.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",file.Length.ToString());
Response.WriteFile(file.FullName);
Response.Flush();