zoukankan
html css js c++ java
将上传文件以二进制形式存入数据库中,并下载数据库中的二进制数据生成对应的文件
以下是读取用户上传的文件,转换成二进制写入数据库:
读取文件转化为二进制写入数据库
byte
[] fileContent
=
new
byte
[
0
];
Stream fileInStream;
int
iSize
=
0
;
iSize
=
FileAttachment.PostedFile.ContentLength;
//
文件大小
if
(iSize
>
1000
*
1024
)
{
lblWrong.Text
=
"
您上传得文件过大,不能超过1000K!
"
;
return
;
}
fileInStream
=
FileAttachment.PostedFile.InputStream;
fileContent
=
new
byte
[iSize];
//
将文件以二进制形式赋值给fileContent
int
iStatus
=
fileInStream.Read(fileContent,
0
, iSize);
以下是读取数据库中的二进制数据转换成对应的文件形式,进行下载:
AttachType 为文件内容类型(MIME)
点下载按钮后进行保存
private
void
UploadBtn_Click(
object
sender, System.EventArgs e)
{
byte
[] tmpAttch
=
(
byte
[])ViewState[
"
BtAttch
"
];
Response.ContentType
=
ViewState[
"
AttachType
"
].ToString().Trim();
//
"application/vnd.ms-excel";
Response.ContentEncoding
=
System.Text.Encoding.Unicode;
string
filename
=
"
CustomDataManager
"
;
Response.AddHeader(
"
Content-Disposition
"
,
"
attachment; filename=
"
+
filename);
this
.Response.Clear();
System.IO.Stream fs
=
this
.Response.OutputStream;
fs.Write(tmpAttch,
0
,tmpAttch.Length);
fs.Close();
this
.Response.End();
}
查看全文
相关阅读:
Linux写时拷贝技术(copy-on-write)
crontab使用进程锁解决冲突
Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio
精确度量Linux下进程占用多少内存的方法
在Linux系统的服务器上使用Memtester进行内存压力测试
How to speed up insertion performance in PostgreSQL
Mongo的备份和恢复(mongodump 和mongorestore )
MongoDB:删除操作
MongoDB插入数据的3种方法
Centos 软连接和硬链接
原文地址:https://www.cnblogs.com/hanguoji/p/426467.html
最新文章
mysql 子查询 合并查询
mysql数据库进阶
mysql数据库常用命令入门
get 传中文,可以通过下面这种方式
spring mvc使用@InitBinder 标签对表单数据绑定
spring+mybatis+shiro入门实例
使用Spring AOP 实现日志管理(简单教程)
mybatis generator 使用教程(生成带注释的实体类)
使用tomcat的jndi方式连接mysql的字符编码设置
docker修改默认存储位置
热门文章
docker hub加速访问设置
docker报错:Failed to restart docker.service: Unit not found.
快速部署docker
ubantu/centos修改系统时间
jenkins添加类ubuntu/centos节点报错
jenkins命令行修改时间
centos/linux/ubuntu在局域网上网
ubuntu的磁盘扩容
Coverity代码扫描工具
linux下生成core dump文件方法及设置
Copyright © 2011-2022 走看看