asp.net关于文件在数据库的存入和读取

2008-02-22 09:36:55来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

最近有个涉及到邮件的活,需要把文件上传到数据库,然后再把文件从数据库里面读出来,进行下载。

找了一些资料之后运用到项目当中。
数据库的结构如下:


USE [EOffice]
GO
/**//****** 对象: Table [dbo].[Group_Files] 脚本日期: 07/20/2006 23:57:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Group_Files](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FileName] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Group_Files_FileName] DEFAULT (''),
[FileBody] [image] NULL,
[FileType] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_Group_Files_FileType] DEFAULT (''),
CONSTRAINT [PK_Group_Files] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
然后我写了一个存储过程,代码如下:
USE [EOffice]
GO
/**//****** 对象: StoredProcedure [dbo].[SendTo_Group_Email] 脚本日期: 07/20/2006 23:59:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


Create PROCEDURE [dbo].[SendTo_Group_Email]
(
@Title varchar(200),
@Content varchar(MAX),
@Area varchar(max),
@Sender varchar(50),
@Dept varchar(50),
@SendToUser varchar(50),
@FileName varchar(200),
@FileBody image,
@FileType varchar(4)
)
AS

INSERT Group_Email (Title,[Content],Area,SendToUser,Dept,Sender,FileName,FileBody,FileType) VALUES (@Title,@Content,@Area,@SendToUser,@Dept,@Sender,@FileName,@FileBody,@FileType)


程序代码如下:
SendEmail.aspx
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendEmail.aspx.cs" Inherits="GroupWork_SendEmail" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6
7<head runat="server">
8 <title>发送邮件</title>
9<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">
10body,td,th {
11 font-size: 9pt;
12}
13body {
14 background-image: url();
15 background-color: #F2F7FB;
16 margin-left: 10px;
17 margin-top: 5px;
18 margin-right: 10px;
19 margin-bottom: 5px;
20}
21-->
22</style></head>
23<script language="vbscript">
24function Select_Local_User(url)
25 dim k
26 k=showModalDialog(url,"","dialogWidth:485px;status:no;dialogHeight:280px")
27 if ubound(split(k,"=0'>$#@&!"))>=0 then
28 document.form1.HiddenField1.value = split(k,"$#@&!")(0)
29 document.form1.txtLocalUser.value = split(k,"$#@&!")(1)
30 end if
31end function
32
33function Select_Remote_User(url)
34 dim k
35 k=showModalDialog(url,"","dialogWidth:485px;status:no;dialogHeight:310px")
36 if ubound(split(k,"=0'>$#@&!"))>=0 then
37 document.form1.HiddenField2.value = split(k,"$#@&!")(0)
38 document.form1.txtRemoteUser.value=split(k,"$#@&!")(1)
39 end if
40end function
41
42</script>
43<body>
44 <form id="form1" method="post" enctype="multipart/form-data" runat="server">
45 <div style="text-align: center">
46 <table border="0" cellpadding="0" cellspacing="0" width="100%">
47 <tr>
48 <td width="1%"><img src="../Images/spacer.gif" width="11" height="1" border="0" alt="" /></td>
49 <td colspan="2"><img src="../Images/spacer.gif" width="209" height="1" border="0" alt="" /></td>
50 <td width="1%"><img src="../Images/spacer.gif" width="12" height="1" border="0" alt="" /></td>
51 <td width="2%"><img src="../Images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
52 </tr>
53 <tr>
54 <td style="height: 35px"><img src="../Images/ye_r1_c1.gif" alt="" name="ye_r1_c1" width="11" height="30" border="0" id="ye_r1_c1" /></td>
55 <td colspan="2" align="left" background="../images/ye_r1_c2.gif" style="height: 35px"><table width="119" border="0" cellspacing="0" cellpadding="0">
56 <tr>
57 <td width="40" height="20">&nbsp;</td>
58 <td width="79" valign="top"><strong>收 文 登 记</strong></td>
59 </tr>
60 </table></td>
61 <td style="height: 35px"><img src="../Images/ye_r1_c3.gif" alt="" name="ye_r1_c3" width="12" height="30" border="0" id="ye_r1_c3" /></td>
62 <td style="height: 35px"></td>
63 </tr>
64 <tr>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子!

下一篇:ASP.NET2.0下利用javascript实现TreeView中的checkbox全选