我做了一个将文件以2进制存储到数据库的程序,例如上传文件,会记录文件的类型 例如 word excel然后再将此文件2进制保存到SQLSERVER中,读取的时候,根据记录的类型生成指定的类型的文件,提供给用户下载,请问 我读取可以获取存储的byte[]数组,但不清楚如何生成文件提供给用户下载,请大侠们指点围观,多谢。
解决方案 »
- Tcp传输数据里面,关于数据结构的问题
- 保存图片路径到sql05中:网上找了很长时间、弄了快一星期了,还是没弄好,请各位好心人进来帮帮,谢谢了
- SQL Server2005新建不了一个新的登录名
- 关于TabControl的问题
- 如何做到串口一有数据,就去读取该串口数据?给个思路,在线等!亲爱的兄弟姐妹们,出手了!
- 两个类同时运行时,后一个类会让前一个类的函数挂起,请教这是为什么
- {"未能加载文件或程序集“SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件。":"SQLServerDAL"} System.Exception {System.IO.FileNotFoundException
- 关于ChangePassword请大家帮忙,看看为什么会有这样的错误?
- 各位大侠帮帮忙,怎么设置listbox中的某条item的高度!
- Winfrom+问下大家用水晶报表是做渲染界面, 还是做预览打印(我只会这个)呢
- VS数据源与控件的bug,不是很明白,麻烦解释一下
- VS WINCE 编码问题 异常“PlatformNotSupportedException”
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++;
}
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[],不需要保存成文件
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();