7 个解决方案
#1
好像是chunk啥的,你搜索一下
#2
File.WriteAllBytes(@"文件的完全限定名",byte数组);
#3
string sPath = "D:\\";//路径
string FileLoad = sPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";//.jpg-.doc -.xls
FileStream fs = new FileStream(FileLoad, FileMode.Create, FileAccess.Write);//创建图片存放路径
BinaryWriter bw = new BinaryWriter(fs);
while (i < bytes.Length)
{
bw.Write(bytes);
i++;
}
#4
代码来自:
http://digga2012.iteye.com/blog/317530
Response.BinaryWrite写Byte[],不需要保存成文件
http://digga2012.iteye.com/blog/317530
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlDataAdapter da=new SqlDataAdapter("select * from tb1",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DataTable dt=ds.Tables["table1"];
string name=System.Configuration.ConfigurationSettings.AppSettings["downloadurl"].ToString() DateTime.Today.ToString("yyyyMMdd") new Random(DateTime.Now.Millisecond).Next(10000).ToString() ".csv";//存放到web.config中downloadurl指定的路径,文件格式为当前日期 4位随机数
FileStream fs=new FileStream(name,FileMode.Create,FileAccess.Write);
StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
sw.WriteLine("自动编号,姓名,年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"] "," dr["vName"] "," dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=" Server.UrlEncode(name));
Response.ContentType = "application/ms-excel";// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.WriteFile(name); // 把文件流发送到客户端
Response.End();
Response.BinaryWrite写Byte[],不需要保存成文件
#5
你应该只保留链接的
#6
Response.Clear();
Response.BufferOutput = false;
Response.ContentEncoding = System.Text.Encoding.UTF8;
string fineName = "test";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fineName + ".xls");
Response.ContentType = "application/ms-excel";
byte[] buffer = new byte[300];
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.Close();
#7
多谢大家了,必须结贴散分!
#1
好像是chunk啥的,你搜索一下
#2
File.WriteAllBytes(@"文件的完全限定名",byte数组);
#3
string sPath = "D:\\";//路径
string FileLoad = sPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";//.jpg-.doc -.xls
FileStream fs = new FileStream(FileLoad, FileMode.Create, FileAccess.Write);//创建图片存放路径
BinaryWriter bw = new BinaryWriter(fs);
while (i < bytes.Length)
{
bw.Write(bytes);
i++;
}
#4
代码来自:
http://digga2012.iteye.com/blog/317530
Response.BinaryWrite写Byte[],不需要保存成文件
http://digga2012.iteye.com/blog/317530
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlDataAdapter da=new SqlDataAdapter("select * from tb1",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DataTable dt=ds.Tables["table1"];
string name=System.Configuration.ConfigurationSettings.AppSettings["downloadurl"].ToString() DateTime.Today.ToString("yyyyMMdd") new Random(DateTime.Now.Millisecond).Next(10000).ToString() ".csv";//存放到web.config中downloadurl指定的路径,文件格式为当前日期 4位随机数
FileStream fs=new FileStream(name,FileMode.Create,FileAccess.Write);
StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
sw.WriteLine("自动编号,姓名,年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"] "," dr["vName"] "," dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=" Server.UrlEncode(name));
Response.ContentType = "application/ms-excel";// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.WriteFile(name); // 把文件流发送到客户端
Response.End();
Response.BinaryWrite写Byte[],不需要保存成文件
#5
你应该只保留链接的
#6
Response.Clear();
Response.BufferOutput = false;
Response.ContentEncoding = System.Text.Encoding.UTF8;
string fineName = "test";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fineName + ".xls");
Response.ContentType = "application/ms-excel";
byte[] buffer = new byte[300];
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.Close();
#7
多谢大家了,必须结贴散分!