- 浏览: 50353 次
- 性别:
- 来自: 西安
最近访客 更多访客>>
最新评论
-
black.angel:
你用的FCK是什么版本的?
EXT中嵌入FCK Editor -
tmartin:
学习了 好东西
EXTJS如何通过JSON与服务器通信
读取文件夹,将文件直接保存到数据库中
前台文件
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="main.aspx.cs"Inherits="CommPage_main"%>
2
3<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<htmlxmlns="http://www.w3.org/1999/xhtml">
6<headrunat="server">
7<title>无标题页</title>
8</head>
9<body>
10<formid="form1"runat="server">
11<div>
12<tablestyle="border:0;width:100%;text-align:right;">
13<tr>
14<tdstyle="height:26px"></td>
15<tdstyle="height:26px"></td>
16<tdstyle="height:26px"><asp:ButtonID="btnSaveToDataBase"runat="server"Height="24px"OnClick="btnSaveToDataBase_Click"Text="图片保存到数据库中"Width="176px"/></td>
17</tr>
18</table>
19</div>
20
21</form>
22</body>
23</html>
24
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1usingSystem;
2usingSystem.Data;
3usingSystem.Configuration;
4usingSystem.Collections;
5usingSystem.Web;
6usingSystem.Web.Security;
7usingSystem.Web.UI;
8usingSystem.Web.UI.WebControls;
9usingSystem.Web.UI.WebControls.WebParts;
10usingSystem.Web.UI.HtmlControls;
11
12usingSystem.Data.SqlClient;
13usingSystem.IO;
14usingSystem.Drawing;
15usingSystem.Drawing.Imaging;
16usingSuntownBase;
17
18publicpartialclassCommPage_main:System.Web.UI.Page
19{
20STSharedST=newSTShared();
21
22protectedvoidPage_Load(objectsender,EventArgse)
23{
24
25}
26
27protectedvoidbtnSaveToDataBase_Click(objectsender,EventArgse)
28{
29inti=0;//文件计数
30
31string[]dirs=Directory.GetFiles(@"D:\aaa\images");
32if(dirs.Length!=0)
33{
34try
35{
36//Response.Write("共有"+dirs.Length+"个文件!");
37foreach(stringdirindirs)
38{
39//Response.Write("<p>"+dir);
40//如果文件类型不匹配,则重新循环
41if((dir.ToLower()).IndexOf(".jpg")==-1&&(dir.ToLower()).IndexOf(".gif")==-1)
42{
43continue;
44}
45else
46{
47i++;//文件计数加1
48}
49
50//C:\Inetpub\wwwroot\CadFormula\images\item_12.jpg
51
52//FileInfofi=newFileInfo(openFileDialog1.PostedFile.FileName);
53
54FileInfofi=newFileInfo(dir);
55intimgdatalen=(int)fi.Length;
56byte[]imgdata=newbyte[imgdatalen];
57Streamimgdatastream=fi.OpenRead();
58intn=imgdatastream.Read(imgdata,0,imgdatalen);
59stringConnectionString="server=.;database=image;uid=sa;pwd=admin";
60SqlConnectionconn=newSqlConnection(ConnectionString);
61
62stringsql="insertinto[image](picture)values(@imgdata)";
63
64SqlCommandcmd=newSqlCommand(sql,conn);
65
66SqlParameterparamData=newSqlParameter("@imgdata",SqlDbType.Image);
67paramData.Value=imgdata;
68cmd.Parameters.Add(paramData);
69
70conn.Open();
71cmd.ExecuteNonQuery();
72conn.Close();
73}
74}
75catch(Exceptionerr)
76{
77Response.Write("出现错误:"+err.Message.ToString());
78}
79finally
80{
81if(i==0)
82{
83ST.MessageBox(Page,"没有匹配的文件!","确定");
84}
85else
86{
87ST.MessageBox(Page,"成功上传"+i.ToString()+"个文件!","确定");
88}
89//最后删除此文件夹下的文件
90}
91}
92}
93}
94
===============================================
下面是读取文件
前台:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="test2.aspx.cs"Inherits="CommPage_test2"%>
2
3<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<htmlxmlns="http://www.w3.org/1999/xhtml">
6<headrunat="server">
7<title>无标题页</title>
8</head>
9<body>
10<formid="form1"runat="server">
11<div>
12<imgid=ImgSpan1border=0src="testimg/select.jpg"><br>
13<imgid=imgborder=0>
14<br/>
15<inputtype=buttonvalue=顺转90度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=1)'"id="Button3">
16<inputtype=buttonvalue=顺转180度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=2)'">
17<inputtype=buttonvalue=逆转90度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=3)'">
18<inputtype=buttonvalue=恢复角度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=0)'">
19<br/>
20<br/>
21<br/>
22<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="图片保存到数据库中"Height="24px"Width="176px"/><br/>
23<br/>
24<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="显示图片"/><br/>
25<br/>
26<br/>
27</div>
28</form>
29</body>
30</html>
31
32
33<scriptlanguage="javascript"<span
前台文件
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="main.aspx.cs"Inherits="CommPage_main"%>
2
3<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<htmlxmlns="http://www.w3.org/1999/xhtml">
6<headrunat="server">
7<title>无标题页</title>
8</head>
9<body>
10<formid="form1"runat="server">
11<div>
12<tablestyle="border:0;width:100%;text-align:right;">
13<tr>
14<tdstyle="height:26px"></td>
15<tdstyle="height:26px"></td>
16<tdstyle="height:26px"><asp:ButtonID="btnSaveToDataBase"runat="server"Height="24px"OnClick="btnSaveToDataBase_Click"Text="图片保存到数据库中"Width="176px"/></td>
17</tr>
18</table>
19</div>
20
21</form>
22</body>
23</html>
24
CS文件
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1usingSystem;
2usingSystem.Data;
3usingSystem.Configuration;
4usingSystem.Collections;
5usingSystem.Web;
6usingSystem.Web.Security;
7usingSystem.Web.UI;
8usingSystem.Web.UI.WebControls;
9usingSystem.Web.UI.WebControls.WebParts;
10usingSystem.Web.UI.HtmlControls;
11
12usingSystem.Data.SqlClient;
13usingSystem.IO;
14usingSystem.Drawing;
15usingSystem.Drawing.Imaging;
16usingSuntownBase;
17
18publicpartialclassCommPage_main:System.Web.UI.Page
19{
20STSharedST=newSTShared();
21
22protectedvoidPage_Load(objectsender,EventArgse)
23{
24
25}
26
27protectedvoidbtnSaveToDataBase_Click(objectsender,EventArgse)
28{
29inti=0;//文件计数
30
31string[]dirs=Directory.GetFiles(@"D:\aaa\images");
32if(dirs.Length!=0)
33{
34try
35{
36//Response.Write("共有"+dirs.Length+"个文件!");
37foreach(stringdirindirs)
38{
39//Response.Write("<p>"+dir);
40//如果文件类型不匹配,则重新循环
41if((dir.ToLower()).IndexOf(".jpg")==-1&&(dir.ToLower()).IndexOf(".gif")==-1)
42{
43continue;
44}
45else
46{
47i++;//文件计数加1
48}
49
50//C:\Inetpub\wwwroot\CadFormula\images\item_12.jpg
51
52//FileInfofi=newFileInfo(openFileDialog1.PostedFile.FileName);
53
54FileInfofi=newFileInfo(dir);
55intimgdatalen=(int)fi.Length;
56byte[]imgdata=newbyte[imgdatalen];
57Streamimgdatastream=fi.OpenRead();
58intn=imgdatastream.Read(imgdata,0,imgdatalen);
59stringConnectionString="server=.;database=image;uid=sa;pwd=admin";
60SqlConnectionconn=newSqlConnection(ConnectionString);
61
62stringsql="insertinto[image](picture)values(@imgdata)";
63
64SqlCommandcmd=newSqlCommand(sql,conn);
65
66SqlParameterparamData=newSqlParameter("@imgdata",SqlDbType.Image);
67paramData.Value=imgdata;
68cmd.Parameters.Add(paramData);
69
70conn.Open();
71cmd.ExecuteNonQuery();
72conn.Close();
73}
74}
75catch(Exceptionerr)
76{
77Response.Write("出现错误:"+err.Message.ToString());
78}
79finally
80{
81if(i==0)
82{
83ST.MessageBox(Page,"没有匹配的文件!","确定");
84}
85else
86{
87ST.MessageBox(Page,"成功上传"+i.ToString()+"个文件!","确定");
88}
89//最后删除此文件夹下的文件
90}
91}
92}
93}
94
===============================================
下面是读取文件
前台:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->1<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="test2.aspx.cs"Inherits="CommPage_test2"%>
2
3<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<htmlxmlns="http://www.w3.org/1999/xhtml">
6<headrunat="server">
7<title>无标题页</title>
8</head>
9<body>
10<formid="form1"runat="server">
11<div>
12<imgid=ImgSpan1border=0src="testimg/select.jpg"><br>
13<imgid=imgborder=0>
14<br/>
15<inputtype=buttonvalue=顺转90度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=1)'"id="Button3">
16<inputtype=buttonvalue=顺转180度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=2)'">
17<inputtype=buttonvalue=逆转90度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=3)'">
18<inputtype=buttonvalue=恢复角度onclick="document.all.ImgSpan.style.filter='progid:DXImageTransform.Microsoft.BasicImage(Rotation=0)'">
19<br/>
20<br/>
21<br/>
22<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="图片保存到数据库中"Height="24px"Width="176px"/><br/>
23<br/>
24<asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="显示图片"/><br/>
25<br/>
26<br/>
27</div>
28</form>
29</body>
30</html>
31
32
33<scriptlanguage="javascript"<span
发表评论
-
关于建立asp.net WEB应用程序时,提示IIS运行的不是asp.net 1.1版的解决办法
2006-07-24 21:49 647关于建立asp.net WEB应用程序时,提示IIS运行的不是 ... -
Asp.Net 学习资源列表
2006-11-16 17:25 592名称:快速入门地址:http://chs.gotdotnet. ... -
给ASP.Net表单增加验证码
2006-11-24 22:09 784给ASP.Net表单增加验证码 一、验证码 对于一个预 ... -
C# 里XML文件读写
2006-11-24 22:14 647已知有一个XML文件(bookstore.xml)如下:< ... -
asp.net页面间数据传递
2007-09-23 00:47 5511. Get(即使用QueryString显 ... -
一些常见的ASP.NET验证码
2007-09-23 11:17 1635一些常见的验证码效果图: ... -
asp.net 验证码类
2007-09-23 11:30 974我们在设计用户登录模块时,经常会用到验证码,可以有效地防止黑 ... -
C#中获取程序当前路径的集中方法
2007-10-11 18:55 533stringstr1=Process.GetCurrent ... -
.NET中的lock
2007-10-13 19:43 1108lock 关键字可将语句块标记为临界区,方法是获取给定对象 ... -
创建ADOKeycap数据库对象
2007-10-13 19:46 581为什么要创建数据库对象?ADOKeycap 必须创建Datab ... -
ASP.net app_Code dll 类中获得当前路径的方法(非页面中)
2007-10-13 20:44 1700在ASP.NET 页面中获得当前路径的方法很多,比如 MapP ... -
ADOKeycap 比 Socut.data.dll 优越在哪?
2007-10-13 20:45 751最近有很多原Socut.data.dl ... -
使用ADOKeycap统计数据
2007-10-13 20:47 543请注意引用: usingSystem.Data.Commo ... -
认识 yueue.ADOKeycap 开源数据库组件
2007-10-13 20:49 714ADOKeycap 是什么?ADOKeycap ... -
yueue.ADOKeycap 开源数据库组件 1.02 下载+反馈 页面
2007-10-13 20:50 7181.02 版本主要改进如下:1.加入了新方法 AddOutPa ... -
添加yueue.ADOKeycap数据库组件到您的项目
2007-10-13 21:17 623为什么要添加引用?您必须通过在您的工程中引用ADOKeycap ... -
使用AODKeycap读取数据
2007-10-13 21:18 757请注意引用: usingSystem. ... -
使用ADOKeycap插入,更新,删除数据
2007-10-13 21:19 717在执行Delete命令时建议只使用Delete From 而不 ... -
在ADOKeycap中使用DataReader读取数据
2007-10-13 21:21 703注意 您在阅读本教程前最好先阅读 <将ADOKeyc ...
相关推荐
C#+存取SqlServer中的Image类型
有一个员工表Employee,需要保存员工照片(Photo)到数据库(sql server)上。员工照片对应的字段是varbinary(max),也就是要存成二进制文件类型(这和以前讨巧地存图片文件路径就不相同了),默认可以为空。
273 实例190 获取窗口文本 273 实例191 判断文件是否正在被使用 274 实例192 在程序中调用.HLP文件 275 实例193 C#中实现文件拖放 276 实例194 文件比较 276 第7章 操作系统与Windows...
SQL Server提供了一个特别的数据类型:image,它是一个包含binary数据的类型。下边这个例子就向你展示了如何将文本或照片放入到数据库中的办法。在这篇文章中我们要看到如何在SQL Server中存储和读取图片。
采用基于WEB的企业计算,采用了世界上最先进的微软技术:C#语言、SqlServer/Access数据库引擎和IIS服务器,性能稳定可靠。数据存取集中控制,避免了数据泄漏的可能。提供数据备份工具,保护系统数据安全。多级的权限...
结合具体实例,说明在Web数据库应用系统中,如何运用ASP.NET技术实现SQL SERVER2000数据库对图片文件进行存储并通过浏览器进行显示。该实例为数据库中多种二进制大对象类型的数据,包括图片、声音、视频及各种...
406 实例283 在C#中附加SQL Server数据库 407 实例284 在C#中附加单文件SQL Server数据库 409 9.12 数据备份恢复 410 实例285 备份SQL Server数据库 410 实例286 还原SQL Server数据库 413...
懒人工作通采用基于WEB的企业计算,采用了世界上最先进的微软技术:C#语言、SqlServer/Access数据库引擎和IIS服务器,性能稳定可靠。数据存取集中控制,避免了数据泄漏的可能。提供数据备份工具,保护系统数据安全。...
懒人工作通 采用基于WEB的企业计算,采用了世界上最先进的微软技术:C#语言、SqlServer数据库引擎和IIS服务器,性能稳定可靠。数据存取集中控制,避免了数据泄漏的可能。提供数据备份工具,保护系统数据安全。多级...
20.4.3 表达式的应用 20.5 数据维护与触发器的应用 20.5.1 添加数据的实现 20.5.2 更新数据的实现 20.5.3 删除数据的实现 20.5.4 在VB.NET中应用触发器20.6 小结第21章 VB 6.0与SQL Server的开发与应用 21.1 VB 6.0...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...