zoukankan
html css js c++ java
图片image和byte处理,fileupload上传图片 Virus
--
这是通过浏览某图片,把他存放到数据库中
string
filename
=
txt_filename.Text;
string
filecomment
=
txt_filecomment.Text;
string
SlaveFileName
=
FileUpload1.PostedFile.FileName;
byte
[] FileContent_img
=
null
;
DateTime UploadTime
=
DateTime.Now.Date;
string
id
=
lbl_id.Text;
RemoteRule remoteRule
=
(RemoteRule)GetRemoteingObjectByType(
typeof
(RemoteRule),
"
remoterule
"
);
DataSet ds
=
new
DataSet();
if
(id
==
""
)
{
ds
=
remoteRule.GetRuleByID(
-
1
);
DataRow dr
=
ds.Tables[
0
].NewRow();
if
(SlaveFileName
!=
""
)
{
//
读取所上传的文件的二进制流
HttpPostedFile file1
=
FileUpload1.PostedFile;
int
filelength
=
Convert.ToInt32(file1.InputStream.Length);
FileContent_img
=
new
byte
[filelength];
file1.InputStream.Read(FileContent_img,
0
, filelength);
//
这里所说的二进制流表现为什么样
}
else
{
SlaveFileName
=
null
;
}
dr[
"
FileName_ch
"
]
=
filename;
dr[
"
FileDesc_ch
"
]
=
filecomment;
dr[
"
SlaveFileName_ch
"
]
=
SlaveFileName;
dr[
"
FileContent_img
"
]
=
FileContent_img;
dr[
"
UploadUser_ch
"
]
=
this
.SystemModuleSettings.UserManage.CurrUserInfo[
"
RealName
"
].ToString();
dr[
"
UploadTime_dt
"
]
=
UploadTime;
ds.Tables[
0
].Rows.Add(dr);
string
result
=
remoteRule.InsRule(ds);
if
(result
==
""
)
{
Response.Write(
"
<script>alert('插入不成功') </script>
"
);
}
else
{
if
(result
!=
"
f
"
)
{
Response.Write(
"
<script>alert('插入成功') </script>
"
);
ViewState[
"
PageState
"
]
=
"
edit
"
;
lbl_id.Text
=
result.Substring(result.IndexOf(
"
,
"
)
+
1
);
setControlsValue();
}
else
{
Response.Write(
"
<script>alert('插入不成功') </script>
"
);
}
}
}
--
显示图片的
byte
[] Image_img
=
(
byte
[])ds_image.Tables[
0
].Rows[
0
][
"
Image_im
"
];
if
(Image_img.Length
==
0
)
return
;
int
filelength
=
Image_img.Length;
string
imageName
=
ds_image.Tables[
0
].Rows[
0
][
1
].ToString()
+
"
1
"
+
"
.jpg
"
;
string
myUrl
=
HttpContext.Current.Server.MapPath(
this
.Request.ApplicationPath)
+
@"
\TempDownLoad\
"
+
imageName;
FileStream fs
=
new
FileStream(myUrl, FileMode.OpenOrCreate);
BinaryWriter w
=
new
BinaryWriter(fs);
w.BaseStream.Write(Image_img,
0
, filelength);
w.Flush();
w.Close();
Image1.ImageUrl
=
Context.Request.ApplicationPath
+
"
/TempDownLoad/
"
+
imageName;
Bitmap bitmap
=
new
Bitmap(myUrl);
Image1.Width
=
bitmap.Width;
Image1.Height
=
bitmap.Height;
【Blog】
http://virusswb.cnblogs.com/
【MSN】
jorden008@hotmail.com
【说明】转载请标明出处,谢谢
反馈文章质量,你可以通过快速通道评论:
查看全文
相关阅读:
几款免费的支持HTML5的音频视频转换软件推荐
2 宽度优先爬虫和带偏好的爬虫(4)
Hadoop源代码分析(三)
Hadoop源代码分析(四)
C# 收邮件
关于Adobe flash palyer 安装出现的问题解决方案
C#调用java类、jar包方法。
EF 4.3 的一些基础使用
.net数据库连接池问题:在同一页面使用一段时间后,提示超时,连接池不够用这类的提示!
使用Google CDN的JSAPI服务来提供加载各类JS库的方法
原文地址:https://www.cnblogs.com/virusswb/p/1205030.html
最新文章
AJAX POST实例二
C# 利用正则表达式验证身份证号
动态HTML事件(Event)小结
asp删除数组中的重复值
将字符串转换成System.Drawing.Color类型
数学符号大全
PHP has encountered an Access Violation at
去掉ASP。NET页面中的VIEWSTATE非存硬盘方法
聚集索引和非聚集索引
css两栏式布局示例
热门文章
【web标准设计】学习、提高、欣赏网站推荐
配置 SQL Server 以便使用 2 GB 以上的物理内存(包括SQL Server 2005)
DbHelper数据操作类
dispaly和visibility的区别
Hadoop源代码分析(二)
搜索引擎蜘蛛爬虫原理
7个免费的在线音频编辑网站推荐
Hadoop源代码分析(一)
4 款基于Django框架的开源软件推荐
2 宽度优先爬虫和带偏好的爬虫(3)
Copyright © 2011-2022 走看看