- 浏览: 260673 次
- 性别:
- 来自: 石家庄
文章分类
最新评论
-
di1984HIT:
写的不错。
设置WebLogic启动内存 -
tda7088:
不错,谢谢
设置WebLogic启动内存 -
java_linkin:
我按照这种方法设置的,但在启动tomcat时还是报内存溢出
Tomcat内存问题(一):Java heap space -
ileson:
...
Tomcat内存问题(一):Java heap space -
helloqidi:
呵呵,谢谢分享
在命令提示符下启动Oracle
Page代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo1.aspx.cs" Inherits="order.Demo.Demo1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Demo1</title> <script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="../js/Global.js"></script> <script type="text/javascript" src="../js/Calendar.js"></script> <link type="text/css" rel="Stylesheet" href="../css/Default.css" /> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" Width="100%" onrowdatabound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand" CssClass="text"> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> <Columns> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <input ID="RadioLine" name="RadioLine" type="radio" value="<%#Eval("accessory_id")%>" /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:BoundField DataField="accessory_id" HeaderText="附件ID" /> <asp:BoundField DataField="order_header_id" HeaderText="订单ID" /> <asp:BoundField DataField="accessory_name" HeaderText="附件名称" /> <asp:BoundField DataField="accessory_description" HeaderText="附件说明" /> <asp:BoundField DataField="creation_date" DataFormatString="{0:d}" HeaderText="创建日期" /> <asp:BoundField DataField="created_by" HeaderText="创建人" /> <asp:BoundField DataField="accessory_size" HeaderText="文件大小" /> <asp:BoundField DataField="accessory_type" HeaderText="文件类型" /> <asp:ButtonField CommandName="DownItem" HeaderText="下载" ShowHeader="True" Text="下载" > <ItemStyle HorizontalAlign="Center" /> </asp:ButtonField> <asp:ButtonField CommandName="DelItem" HeaderText="删除" ShowHeader="True" Text="删除" > <ItemStyle HorizontalAlign="Center" /> </asp:ButtonField> </Columns> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:GridView> <asp:FileUpload ID="FileUpload1" runat="server" ToolTip="附件上传" /> <asp:Button ID="BtnUpload" runat="server" Text="上传" OnClick="BtnUpload_Files" /> <input type="hidden" id="hidden_id" runat=server/> </form> </body> </html> <script language="javascript" type="text/javascript"> // 注销 function fn_DelItem(cellstring) { if (!confirm("确定要删除附件吗?")) { return false; } return true; } // 注销 function fn_DownItem(cellstring) { return true; } </script>
C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using System.IO; using System.Data.OracleClient; using order.Components; using order.commons; namespace order.Demo { public partial class Demo1 : System.Web.UI.Page { private Database db = new Database(); protected void Page_Load(object sender, EventArgs e) { // 注册单选按钮 if (!this.IsStartupScriptRegistered("Startup")) { this.RegisterStartupScript("Startup", RegisterScript.RadioRowSelected(hidden_id.ClientID)); } if(!Page.IsPostBack) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("select oa.accessory_id, oa.order_header_id, oa.accessory_name,oa.accessory_description, "); sqlBuilder.Append("oa.creation_date, oa.created_by, oa.accessory_size, oa.accessory_type "); sqlBuilder.Append("from oe_accessories oa "); sqlBuilder.Append("where 1 = 1 "); DataSet ds = db.returnds(sqlBuilder.ToString()); this.GridView1.DataSource = ds.Tables[0].DefaultView; this.GridView1.DataBind(); } } /// <summary> /// 测试上传文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void BtnUpload_Files(object sender, EventArgs e) { string fileName = "";// 文件名 string filePath = "";// 文件路径 string fileType = "";// 文件类型 string accessory_id = ""; int fileSize = 0; // 文件大小 Stream fis;// 上传文件流 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("insert into oe_accessories oa ( "); sqlBuilder.Append("accessory_id,order_header_id,accessory_name,accessory_description, "); sqlBuilder.Append("accessory_data,creation_date,created_by,oa.accessory_size,oa.accessory_type ) "); sqlBuilder.Append("values( "); sqlBuilder.Append(":accessory_id,:order_header_id,:accessory_name,:accessory_description, "); sqlBuilder.Append(":accessory_data,:creation_date,:created_by,:accessory_size,:accessory_type ) "); // 设置参数 OracleParameter[] orclParams = new OracleParameter[] { new OracleParameter("accessory_id", OracleType.VarChar), new OracleParameter("order_header_id", OracleType.VarChar), new OracleParameter("accessory_name", OracleType.VarChar), new OracleParameter("accessory_description", OracleType.VarChar), new OracleParameter("accessory_data", OracleType.Blob), new OracleParameter("creation_date", OracleType.DateTime), new OracleParameter("created_by", OracleType.VarChar), new OracleParameter("accessory_size", OracleType.Int32), new OracleParameter("accessory_type", OracleType.VarChar) }; HttpFileCollection hfc = Request.Files;// 获取上载文件集合 // 循环获取单个上载文件 for (int i = 0; i < hfc.Count; i++) { HttpPostedFile hpf = hfc.Get(i); fileName = Path.GetFileName(hpf.FileName); filePath = Path.GetDirectoryName(hpf.FileName); fileType = Path.GetExtension(hpf.FileName).ToLower(); fileName = fileName.Substring(0, (fileName.LastIndexOf("."))); // 获取文件流大小 fileSize = hpf.ContentLength; if (fileSize < 1) { return; } // 声明等长byte数组 byte[] buffers = new byte[fileSize]; // 获取文件流 fis = hpf.InputStream; // 文件保存到缓存 fis.Read(buffers, 0, fileSize); accessory_id = db.SequencesGenerator("SEQ_OE_ACCESSORIES"); orclParams[0].Value = accessory_id; orclParams[1].Value = ""; orclParams[2].Value = fileName; orclParams[3].Value = fileName; orclParams[4].Value = buffers; orclParams[4].Size = buffers.Length; orclParams[5].Value = DateTime.Now.ToShortDateString(); orclParams[6].Value = ""; orclParams[7].Value = fileSize; orclParams[8].Value = fileType; db.RunOracleCommand(sqlBuilder.ToString(), orclParams); MessageBox msg = new MessageBox(this); msg.Show("文件上传成功!"); msg.RefreshUrl("../Demo/Demo1.aspx"); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { // 改变背景颜色 if (e.Row.RowType == DataControlRowType.Header) { // } if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onclick", "fn_RadioRowSingle(this,event)"); e.Row.Attributes.Add("class", e.Row.RowIndex % 2 == 0 ? "rowOdd" : "rowEven"); e.Row.Attributes.Add("oldClass", e.Row.RowIndex % 2 == 0 ? "rowOdd" : "rowEven"); e.Row.Attributes.Add("onmouseover", "lastBackgroundColor=this.className;this.className='rowCurrent'"); e.Row.Attributes.Add("onmouseout", "this.className=lastBackgroundColor;"); // 绑定按钮 int CellsCount = e.Row.Cells.Count; LinkButton BtnDownItem = e.Row.Cells[CellsCount - 2].Controls[0] as LinkButton; LinkButton BtnDelItem = e.Row.Cells[CellsCount - 1].Controls[0] as LinkButton; string RowCells = "role_id=" + e.Row.Cells[1].Text.Trim(); BtnDownItem.Attributes.Add("onclick", "return fn_DownItem('" + RowCells + "');"); BtnDelItem.Attributes.Add("onclick", "return fn_DelItem('" + RowCells + "');"); } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { // 删除 if (e.CommandName == "DelItem") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = this.GridView1.Rows[index]; string accessory_id = row.Cells[1].Text.Trim(); List<String> BatchSQL = new List<String>(); string newSQL = "delete from oe_accessories oa where 1 = 1 and oa.accessory_id = '" + accessory_id + "' "; BatchSQL.Add(newSQL); db.RunOracleCommandBatch(BatchSQL); MessageBox msg = new MessageBox(this); msg.Show("文件删除成功!"); msg.RefreshUrl("../Demo/Demo1.aspx"); } // 下载-直接下载文件流 if (e.CommandName == "DownItemTest") { try { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = this.GridView1.Rows[index]; string accessory_id = row.Cells[1].Text.Trim(); // 取出后写到一个文件中 FileStream fos; // 以二进制形式将基元类型写入流 BinaryWriter writer; int bufferSize = 1024; // 该字节的BLOB缓冲区,以填补getbytes byte[] bytes = new byte[bufferSize]; long retval; long startIndex = 0; string fileName = ""; StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("select oa.accessory_name,oa.accessory_data from oe_accessories oa where 1 = 1 and oa.accessory_id ='").Append(accessory_id).Append("' "); OracleDataReader dr = db.returndr(sqlBuilder.ToString()); while (dr.Read()) { // 读文件名 fileName = dr["accessory_name"].ToString(); // 创建一个文件 fos = new FileStream(Path.GetTempPath() + fileName, FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(fos); startIndex = 0; retval = dr.GetBytes(1, startIndex, bytes, 0, bufferSize); while (retval == bufferSize) { writer.Write(bytes); writer.Flush(); startIndex += bufferSize; retval = dr.GetBytes(1, startIndex, bytes, 0, bufferSize); } writer.Write(bytes, 0, (int)retval); writer.Flush(); // 释放资源 writer.Close(); fos.Close(); } } catch (Exception ex) { order.SystemError.SystemLog(ex.Message); } finally { db.Close(); } } // 下载-显示打开和保存 if (e.CommandName == "DownItem") { try { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = this.GridView1.Rows[index]; string accessory_id = row.Cells[1].Text.Trim(); // 取出后写到一个文件中 FileStream fos; // 以二进制形式将基元类型写入流 BinaryWriter writer; int fileSize = 1024; long retval; long startIndex = 0; string fileName = ""; string fileType = ""; StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("select oa.accessory_name,oa.accessory_data,oa.accessory_size,oa.accessory_type "); sqlBuilder.Append("from oe_accessories oa where 1 = 1 and oa.accessory_id ='").Append(accessory_id).Append("' "); OracleDataReader dr = db.returndr(sqlBuilder.ToString()); while (dr.Read()) { // 读文件名 fileName = dr["accessory_name"].ToString(); fileSize = int.Parse(dr["accessory_size"].ToString()); fileType = dr["accessory_type"].ToString(); // 该字节的BLOB缓冲区,以填补getbytes byte[] bytes = new byte[fileSize]; // 创建一个文件 fos = new FileStream(Path.GetTempPath() + fileName, FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(fos); startIndex = 0; retval = dr.GetBytes(1, startIndex, bytes, 0, fileSize); while (retval == fileSize) { writer.Write(bytes); writer.Flush(); startIndex += fileSize; retval = dr.GetBytes(1, startIndex, bytes, 0, fileSize); } writer.Write(bytes, 0, (int)retval); writer.Flush(); // 释放资源 writer.Close(); fos.Close(); this.Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; string ct = this.DownFile_ContentType(fileType); Response.ContentType = ct; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length", bytes.Length.ToString()); Response.BinaryWrite(bytes); //二进制文件 Response.Flush(); Response.End(); } } catch (Exception ex) { order.SystemError.SystemLog(ex.Message); } finally { db.Close(); } } } /// <summary> /// 下载文件类型 /// </summary> /// <param name="fileType"></param> /// <returns></returns> protected string DownFile_ContentType(string fileType) { string result = ""; try { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("select pc.type_description from params_codelist pc "); sqlBuilder.Append("where 1 = 1 "); sqlBuilder.Append("and pc.kind_code = 'CONTENT_TYPE' "); sqlBuilder.Append("and pc.type_value = '").Append(fileType).Append("' "); OracleDataReader dr = db.returndr(sqlBuilder.ToString()); while (dr.Read()) { result = dr["type_description"].ToString().Trim(); } } catch (Exception ex) { order.SystemError.SystemLog(ex.Message); } finally { db.Close(); } if(result.Length <= 0 ) { result = "text/plain"; } return result; } } }
发表评论
-
C#中GRIDVIEW单选按钮使用
2011-12-12 10:14 3703page代码: <asp:GridView ID=&q ... -
js验证及限制文本框输入
2011-10-28 22:06 912下面都是我收集的一些比较常用的正则表达式,因为平常可能在表单验 ... -
GridView隐藏列取值解决方法
2011-10-28 21:59 1549当在GridView中取值,某列数据隐藏又需要传递取值时,如果 ... -
获取IE浏览器模式
2011-10-26 10:28 1078function getIeCompatMode() { ... -
FF与IE下javascript计算屏幕尺寸
2011-10-26 10:20 1075以下是IE新开页面屏幕计算默认值: FF与IE都支持 ... -
配置ASP.NET平台时遇到的“访问IIS元数据库失败”
2011-10-21 09:03 1237大意就是没有服务器上当前IIS进程没有访问元数据库的权限… ... -
安装IIS 6.0注意问题
2011-10-20 22:25 1135下载地址:http://qfzx.nhedu.net/So ... -
Javascript 操作select标记中options的方法
2011-10-20 15:20 9981 检测是否有选中 if (objSelect.select ... -
ASP.NET中TextBox控件设置ReadOnly="true"后台取不到值
2011-10-17 14:36 1893当TextBox设置了ReadOnly="true& ... -
showModalDialog打开窗口时不跳入新页面设置
2011-10-15 17:47 1330在showModalDialog打开的窗口中加入 &l ... -
访问iis时名称以无效字符开头解决办法
2011-10-11 11:06 3508由于IIS出问题,重安了IIS,结果出现调试ASP.n ... -
Sharepoint BDC中常用的数据连接串写法
2011-08-15 10:46 1167SQL Server Server=<DATAB ... -
WINDOWS 安装Oracle 10g提示要求的结果: 5.0,5.1,5.2,6.0 之一解决方法
2011-08-12 14:49 3397在WIN7上安装oracle 10g时,提示如下信息: ... -
Moss2007 如何删除失败的SSP
2011-08-03 19:31 1250对MOSS2007 来讲,建立失败的SSP是不允许删 ... -
Windows Server 2008 中如何修改域密码策略
2011-07-22 08:52 2034修改方式: 不像 Windows Server 200 ... -
手动完全卸载VS2008说明
2011-07-21 23:18 2473转到“控制面板”并启动“添加/删除程序” 删除所有 Vis ... -
WINDOWS 7 安装IIS服务
2011-07-21 23:09 1087一、进入Windows 7的 控制面板 ,选择左侧的 打开或 ...
相关推荐
在c#中实现上传文件到数据库和从数据库下载文件的源代码
修正了大文件上传或下载时服务器超时的Bug. 可上传500M以内的单个文件.(在空间大小足够的前提下) 2.修正了客户端上传文件的时间与服务器时间不同步的Bug, 同时在充分考虑服务器性能的前提下,给客户端提供了正...
修改:1.删除时提示确认;2.删除数据库文件记录时同时删除服务器上的文件;3.将文件命名用Tick实现
我的C#结课设计,附件的上传下载和权限没做,其他的邮箱功能基本实现,还附上文档和数据库
明日科技出版的c#开发典型模块大全配套光盘,要的可以下载,因大小受限,分开上传! 第1章 认识C#及开发环境 1.1 C#概述 1.1.1 C#发展历程 1.1.2 C#语言编程环境 1.2.NETFramework2.0简介 1.2.1 什么是....
23.5.2 从FTP服务器下载指定版本 628 23.5.3 定时升级设置 630 第24章 Windows应用程序打包与部署境 24.1 Windows Installer简介 634 24.2 Windows应用程序部署 634 24.2.1 创建部署项目 634 24.2.2 可...
明日科技出版的c#开发典型模块大全配套光盘,要的可以下载,因大小受限,分开上传! 第1章 认识C#及开发环境 1.1 C#概述 1.1.1 C#发展历程 1.1.2 C#语言编程环境 1.2.NETFramework2.0简介 1.2.1 什么是....
23.5.2 从FTP服务器下载指定版本 23.5.3 定时升级设置 第24章 Windows应用程序打包与部署境 24.1 WindowsInstaller简介 24.2 Windows应用程序部署 24.2.1 创建部署项目 24.2.2 可选的部署功能 24.3 安装及卸载...
8.3.4 为邮件上传多个附件 193 8.3.5 邮件接收实现 194 8.3.6 查看邮件详细信息 196 8.3.7 下载附件的实现 197 8.3.8 删除邮件实现 198 8.3.9 用户管理 198 第9章 短信群发模块 ...
须已安装IIS Web 6.0以上服务 (从Windows组件中安装IIS) 2、须已安装 Microsoft .NET Framework v2.0 3、使用 Microsoft SQL Server数据库,确保服务已开启。 支持 Microsoft SQL server 2000 和 Microsoft ...
功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来...
基于ASP.NET4.0 WEB版的 大文件上传实例,带进度条显示,可方便移植到ASP.NET4.0 WEB项目中。
本人前段时间做邮件系统时使用的附件上传,可以直接将文件上传到ORACLE,并且从oracle直接读取和下载,并且步步都有注释,一般人都能看懂!欢迎下载!中间有不完善的地方也希望兄弟们能给予改正
主要介绍了jQuery结合C#实现上传文件的方法,涉及C#文件上传的相关技巧,需要的朋友可以参考下