Imports System.Data.SqlClient Imports System.IO Imports System.XmlPublic Class NewMulDoc Inherits System.Web.UI.Page Protected WithEvents UP_FILE As System.Web.UI.HtmlControls.HtmlInputFile Private Sub addnewdoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewdoc.Click Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称) VALUES (@DocuID, @DocuType, @DocuName)") Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection) 'HttpPostedFile对象,用于读取图象文件属性 Try Dim UpFile As HttpPostedFile = UP_FILE.PostedFile Dim FileLength = 0 '记录文件长度变量 FileLength = UpFile.ContentLength If FileLength <> 0 Then Dim StreamObject As System.IO.Stream = UpFile.InputStream '文件临时储存Byte数组 Dim FileByteArray(FileLength) As Byte '读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2) '读文件内容到FileByteArray数组 StreamObject.Read(FileByteArray, 0, FileLength) StreamObject.Read(FileByteArray, 0, FileLength) com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name DeviceConnection.Open() com2.ExecuteNonQuery() DeviceConnection.Close() DocCloseLabel.Text = "添加成功" Else addnewMessage.Text = "<p><b>请选择正确的文件</b>" End If Catch ex As Exception Response.Write(ex.Message) End Try End Sub
Private Sub addnewdoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewdoc.Click Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称, 创建人,创建日期,文档备注,文档内容) VALUES (@DocuID, @DocuType, @DocuName, @DocuMen,@DocuData,@DocuDemo,@DocuCon)") Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection) 'HttpPostedFile对象,用于读取图象文件属性 Try Dim UpFile As HttpPostedFile = UP_FILE.PostedFile Dim FileLength = 0 '记录文件长度变量 FileLength = UpFile.ContentLength If FileLength <> 0 Then Dim StreamObject As System.IO.Stream = UpFile.InputStream '文件临时储存Byte数组 Dim FileByteArray(FileLength) As Byte '读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2) '读文件内容到FileByteArray数组 StreamObject.Read(FileByteArray, 0, FileLength) StreamObject.Read(FileByteArray, 0, FileLength) com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name com2.Parameters.Add("@DocuMen", SqlDbType.Char, 40).Value = newdocbox2.Text com2.Parameters.Add("@DocuData", SqlDbType.DateTime, FileLength).Value = newdocbox3.Text com2.Parameters.Add("@DocuDemo", SqlDbType.VarChar, 1000).Value = newdocbox4.Text com2.Parameters.Add("@DocuCon", SqlDbType.Binary, FileLength).Value = FileByteArray DeviceConnection.Open() com2.ExecuteNonQuery() DeviceConnection.Close() DocCloseLabel.Text = "添加成功" DocAddPanel.Visible = False DocClosePanel.Visible = True Else addnewMessage.Text = "<p><b>请选择正确的文件</b>" End If Catch ex As Exception Response.Write(ex.Message) End Try End Sub
vb的 Imports System.Data.SqlClient Imports System.IO Imports System.XmlPublic Class NewMulDoc Inherits System.Web.UI.Page Protected WithEvents DeviceConnection As SqlClient.SqlConnection Protected WithEvents UP_FILELabel As System.Web.UI.WebControls.Label Protected WithEvents newdocLabel1 As System.Web.UI.WebControls.Label Protected WithEvents newdocbox1 As System.Web.UI.WebControls.TextBox Protected WithEvents newdocLabel2 As System.Web.UI.WebControls.Label Protected WithEvents newdocbox2 As System.Web.UI.WebControls.TextBox Protected WithEvents newdocLabel3 As System.Web.UI.WebControls.Label Protected WithEvents newdocbox3 As System.Web.UI.WebControls.TextBox Protected WithEvents newdocLabel4 As System.Web.UI.WebControls.Label Protected WithEvents newdocbox4 As System.Web.UI.WebControls.TextBox Protected WithEvents addnewMessage As System.Web.UI.WebControls.Label Protected WithEvents addnewdoc As System.Web.UI.WebControls.Button Protected WithEvents DocAddPanel As System.Web.UI.WebControls.Panel Protected WithEvents Table2 As System.Web.UI.HtmlControls.HtmlTable Protected WithEvents DocCloseLabel As System.Web.UI.WebControls.Label Protected WithEvents DocClosePanel As System.Web.UI.WebControls.Panel Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton Protected WithEvents UP_FILE As System.Web.UI.HtmlControls.HtmlInputFile#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 Dim acm As AccountManager = New AccountManager(Me) If (acm.IsAuthenticated() <> True) Then Response.Write("<script language=javascript>alert('您没有登陆,无法使用本系统,请重新登陆');window.location='../logon/logon.aspx';</script>") Response.Cache.SetExpires(Now) Response.End() 'Response.Redirect("../logon/logon.aspx") End If If (Trim(Session("GroupName")) = "领导") Then Response.Write("<script language=javascript>alert('您没有此权限,请重新登陆');window.location='../logon/logon.aspx';</script>") Response.Cache.SetExpires(Now) Response.End() 'Response.Redirect("../logon/logon.aspx") End If getConnection() End Sub Private Sub getConnection() Try If (DeviceConnection Is Nothing) Then Dim str = Context.GetConfig("appSettings")("dsn") DeviceConnection = New SqlConnection(str) End If Catch e As Exception Response.Write(e.Message) End Try End Sub '############################################## '多文档信息添加处理 '############################################## Private Sub addnewdoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewdoc.Click Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称, 创建人,创建日期,文档备注,文档内容) VALUES (@DocuID, @DocuType, @DocuName, @DocuMen,@DocuData,@DocuDemo,@DocuCon)") Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection) 'HttpPostedFile对象,用于读取图象文件属性 Try Dim UpFile As HttpPostedFile = UP_FILE.PostedFile Dim FileLength = 0 '记录文件长度变量 FileLength = UpFile.ContentLength If FileLength <> 0 Then Dim StreamObject As System.IO.Stream = UpFile.InputStream '文件临时储存Byte数组 Dim FileByteArray(FileLength) As Byte '读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2) '读文件内容到FileByteArray数组 StreamObject.Read(FileByteArray, 0, FileLength) If Trim(newdocbox1.Text) = "" Then addnewMessage.Text = "文档编号不能为空" Exit Sub End If If Trim(newdocbox1.Text) = "" Then addnewMessage.Text = "文档编号不能为空" Exit Sub End If If Trim(newdocbox3.Text) <> "" Then If Not IsDate(Trim(newdocbox3.Text)) Then addnewMessage.Text = "创建日期应该是日期" Exit Sub End If End If StreamObject.Read(FileByteArray, 0, FileLength) com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name com2.Parameters.Add("@DocuMen", SqlDbType.Char, 40).Value = newdocbox2.Text com2.Parameters.Add("@DocuData", SqlDbType.DateTime, FileLength).Value = newdocbox3.Text com2.Parameters.Add("@DocuDemo", SqlDbType.VarChar, 1000).Value = newdocbox4.Text com2.Parameters.Add("@DocuCon", SqlDbType.Binary, FileLength).Value = FileByteArray Dim ada As New SqlClient.SqlDataAdapter("select * from 多文档信息表 where 文档编号='" & Trim(newdocbox1.Text) & "'", DeviceConnection) Dim ds As New DataSet() ada.Fill(ds, "beijian") If ds.Tables(0).Rows.Count > 0 Then addnewMessage.Text = "此文档编号已经存在了" Exit Sub End If DeviceConnection.Open() com2.ExecuteNonQuery() DeviceConnection.Close() DocCloseLabel.Text = "添加成功" DocAddPanel.Visible = False DocClosePanel.Visible = True Else addnewMessage.Text = "<p><b>请选择正确的文件</b>" End If Catch ex As Exception Response.Write(ex.Message) End Try End Sub End Class
Dim strCon As String strCon = "SERVER=yuankena;DATABASE=CRM;UID=sa;PWD=;" Dim sqlcmd2 As New String("INSERT INTO dicUser(UserID, UserName, UserPwd, UserNOte,img) VALUES (@UserID, @UserName, @UserPwd, @UserNOte,@Img)") Dim com2 As New SqlClient.SqlCommand(sqlcmd2, New SqlClient.SqlConnection(strCon)) 'HttpPostedFile对象,用于读取图象文件属性 Dim UpFile As HttpPostedFile = txtImg.PostedFile Dim FileLength = 0 '记录文件长度变量 FileLength = UpFile.ContentLength If FileLength <> 0 Then Dim StreamObject As System.IO.Stream = UpFile.InputStream '文件临时储存Byte数组 Dim FileByteArray(FileLength) As Byte '读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2) '读文件内容到FileByteArray数组 StreamObject.Read(FileByteArray, 0, FileLength) StreamObject.Read(FileByteArray, 0, FileLength) com2.Parameters.Add("@UserID", SqlDbType.NVarChar, 40).Value = txtUserID.Text com2.Parameters.Add("@UserName", SqlDbType.NVarChar, 40).Value = txtUserName.Text com2.Parameters.Add("@UserPwd", SqlDbType.NVarChar, 256).Value = txtUserPwd.Text com2.Parameters.Add("@UserNOte", SqlDbType.NVarChar, 40).Value = txtUserNote.Text com2.Parameters.Add("@Img", SqlDbType.Binary, FileLength).Value = FileByteArray com2.Connection.Open() com2.ExecuteNonQuery() Else End If
输出文件 Imports System.Data.SqlClient Imports System.IO Imports System.Xml Public Class Doc_View_Detail Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 '查询数据库图像id Dim ImgID = Request.QueryString("ImgID") Dim con As SqlClient.SqlConnection '查询sql Dim str = Context.GetConfig("appSettings")("dsn") con = New SqlConnection(str) Dim SqlCmd = "SELECT * from 多文档信息表 where 文档编号='" & ImgID & "'" Try con.Open() Dim ada As New SqlClient.SqlDataAdapter(SqlCmd, con) Dim ds As New DataSet() ada.Fill(ds, "wendang") '设定输出文件类型 'Response.AddHeader("Content-Disposition", "attachment; filename=" & ds.Tables(0).Rows(0).Item("文件名称")) Response.ContentType = Trim(ds.Tables(0).Rows(0).Item("文档类型")) '输出图象文件二进制数制 Dim FileByteArray() As Byte = ds.Tables(0).Rows(0).Item("文档内容") Dim s = ds.Tables(0).Rows(0).Item("文档内容") s = FileByteArray.Length Response.OutputStream.Write(ds.Tables(0).Rows(0).Item("文档内容"), 0, CInt(s)) con.Close() Catch ex As Exception Response.Write(ex.Message) End Try End SubEnd Class
功能有;
1.图片的存入数据库.
2.从数据库取出显示在一个页面.
3.在另外一个页面调用显示图片页面,从而达到在一个页面的指定位置显示某一个数据库中的图片.
-------------------------------------------------
不过这些代码还需要整理
To: yohomonkey(ht)
我会把整理好的代码重发一份给你!
-------------------------------------------------
谁需要的话,给我发短信,或在这里留个联系方式!
可以发到[email protected]
收到!thanks!
正在研究c#!呵呵呵
email:[email protected]
[email protected]
[email protected]
Imports System.IO
Imports System.XmlPublic Class NewMulDoc
Inherits System.Web.UI.Page
Protected WithEvents UP_FILE As System.Web.UI.HtmlControls.HtmlInputFile Private Sub addnewdoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewdoc.Click
Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称) VALUES (@DocuID, @DocuType, @DocuName)")
Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection)
'HttpPostedFile对象,用于读取图象文件属性
Try
Dim UpFile As HttpPostedFile = UP_FILE.PostedFile
Dim FileLength = 0
'记录文件长度变量
FileLength = UpFile.ContentLength
If FileLength <> 0 Then
Dim StreamObject As System.IO.Stream = UpFile.InputStream
'文件临时储存Byte数组
Dim FileByteArray(FileLength) As Byte
'读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2)
'读文件内容到FileByteArray数组
StreamObject.Read(FileByteArray, 0, FileLength)
StreamObject.Read(FileByteArray, 0, FileLength)
com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text
com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType
com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name
DeviceConnection.Open()
com2.ExecuteNonQuery()
DeviceConnection.Close()
DocCloseLabel.Text = "添加成功" Else
addnewMessage.Text = "<p><b>请选择正确的文件</b>"
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try End Sub
Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称, 创建人,创建日期,文档备注,文档内容) VALUES (@DocuID, @DocuType, @DocuName, @DocuMen,@DocuData,@DocuDemo,@DocuCon)")
Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection)
'HttpPostedFile对象,用于读取图象文件属性
Try
Dim UpFile As HttpPostedFile = UP_FILE.PostedFile
Dim FileLength = 0
'记录文件长度变量
FileLength = UpFile.ContentLength
If FileLength <> 0 Then
Dim StreamObject As System.IO.Stream = UpFile.InputStream
'文件临时储存Byte数组
Dim FileByteArray(FileLength) As Byte
'读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2)
'读文件内容到FileByteArray数组
StreamObject.Read(FileByteArray, 0, FileLength)
StreamObject.Read(FileByteArray, 0, FileLength)
com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text
com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType
com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name
com2.Parameters.Add("@DocuMen", SqlDbType.Char, 40).Value = newdocbox2.Text
com2.Parameters.Add("@DocuData", SqlDbType.DateTime, FileLength).Value = newdocbox3.Text
com2.Parameters.Add("@DocuDemo", SqlDbType.VarChar, 1000).Value = newdocbox4.Text
com2.Parameters.Add("@DocuCon", SqlDbType.Binary, FileLength).Value = FileByteArray DeviceConnection.Open()
com2.ExecuteNonQuery()
DeviceConnection.Close() DocCloseLabel.Text = "添加成功"
DocAddPanel.Visible = False
DocClosePanel.Visible = True
Else
addnewMessage.Text = "<p><b>请选择正确的文件</b>"
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try End Sub
email:[email protected]
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="NewMulDoc.aspx.vb" Inherits="PetroFM.NewMulDoc" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>NewMulDoc</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" defer>
function check()
{
window.opener.document.Form1.urlMul.value="submit";
window.opener.document.Form1.submit();
self.close();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" encType="multipart/form-data" runat="server">
<asp:Panel id="DocAddPanel" runat="server">
<TABLE id="Table2" style="FONT-SIZE: 12px" cellSpacing="0" cellPadding="0" width="100%" align="left" border="0" RUNAT="server">
<TR>
<TD>
<asp:Label id="UP_FILELabel" runat="server" Width="163px">提交新文档</asp:Label></TD>
<TD>
<INPUT id="UP_FILE" style="WIDTH: 277px; HEIGHT: 22px" type="file" size="27" name="UP_FILE" RUNAT="server">
</TD>
</TR>
<TR>
<TD>
<asp:Label id="newdocLabel1" runat="server" Width="157px">文档编号</asp:Label> </TD>
<TD>
<asp:textbox id="newdocbox1" RUNAT="server" WIDTH="126px"></asp:textbox></TD>
</TR>
<TR>
<TD>
<asp:Label id="newdocLabel2" runat="server" Width="163px">创建人 </asp:Label></TD>
<TD>
<asp:textbox id="newdocbox2" RUNAT="server" WIDTH="127px"></asp:textbox></TD>
</TR>
<TR>
<TD>
<asp:Label id="newdocLabel3" runat="server" Width="167px">创建日期</asp:Label> </TD>
<TD>
<asp:textbox id="newdocbox3" RUNAT="server" WIDTH="126px"></asp:textbox></TD>
</TR>
<TR>
<TD>
<asp:Label id="newdocLabel4" runat="server" Width="169px">文档备注</asp:Label> </TD>
<TD>
<asp:textbox id="newdocbox4" RUNAT="server" WIDTH="275px"></asp:textbox></TD>
</TR>
<TR>
<TD>
<asp:label id="addnewMessage" RUNAT="server" FORECOLOR="red"></asp:label></TD>
<TD>
<asp:button id="addnewdoc" RUNAT="server" WIDTH="63px" TEXT="添加"></asp:button></TD>
</TR>
</TABLE>
</asp:Panel>
<asp:Panel id="DocClosePanel" runat="server" Visible="False">
<asp:label id="DocCloseLabel" RUNAT="server" FORECOLOR="red"></asp:label>
<INPUT id="Button1" style="FONT-SIZE: 12px" onclick="javascript:check()" type="button" value="关闭" name="DocCloseButton" runat="server" Width="54px">
</asp:Panel>
</form>
</body>
</HTML>
Imports System.Data.SqlClient
Imports System.IO
Imports System.XmlPublic Class NewMulDoc
Inherits System.Web.UI.Page
Protected WithEvents DeviceConnection As SqlClient.SqlConnection
Protected WithEvents UP_FILELabel As System.Web.UI.WebControls.Label
Protected WithEvents newdocLabel1 As System.Web.UI.WebControls.Label
Protected WithEvents newdocbox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents newdocLabel2 As System.Web.UI.WebControls.Label
Protected WithEvents newdocbox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents newdocLabel3 As System.Web.UI.WebControls.Label
Protected WithEvents newdocbox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents newdocLabel4 As System.Web.UI.WebControls.Label
Protected WithEvents newdocbox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents addnewMessage As System.Web.UI.WebControls.Label
Protected WithEvents addnewdoc As System.Web.UI.WebControls.Button
Protected WithEvents DocAddPanel As System.Web.UI.WebControls.Panel
Protected WithEvents Table2 As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents DocCloseLabel As System.Web.UI.WebControls.Label
Protected WithEvents DocClosePanel As System.Web.UI.WebControls.Panel
Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents UP_FILE As System.Web.UI.HtmlControls.HtmlInputFile#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim acm As AccountManager = New AccountManager(Me)
If (acm.IsAuthenticated() <> True) Then
Response.Write("<script language=javascript>alert('您没有登陆,无法使用本系统,请重新登陆');window.location='../logon/logon.aspx';</script>")
Response.Cache.SetExpires(Now)
Response.End()
'Response.Redirect("../logon/logon.aspx")
End If
If (Trim(Session("GroupName")) = "领导") Then
Response.Write("<script language=javascript>alert('您没有此权限,请重新登陆');window.location='../logon/logon.aspx';</script>")
Response.Cache.SetExpires(Now)
Response.End()
'Response.Redirect("../logon/logon.aspx")
End If getConnection() End Sub Private Sub getConnection()
Try
If (DeviceConnection Is Nothing) Then
Dim str = Context.GetConfig("appSettings")("dsn")
DeviceConnection = New SqlConnection(str) End If
Catch e As Exception
Response.Write(e.Message)
End Try
End Sub '##############################################
'多文档信息添加处理
'############################################## Private Sub addnewdoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewdoc.Click
Dim sqlcmd2 As New String("INSERT INTO 多文档信息表(文档编号, 文档类型, 文件名称, 创建人,创建日期,文档备注,文档内容) VALUES (@DocuID, @DocuType, @DocuName, @DocuMen,@DocuData,@DocuDemo,@DocuCon)")
Dim com2 As New SqlClient.SqlCommand(sqlcmd2, DeviceConnection)
'HttpPostedFile对象,用于读取图象文件属性
Try
Dim UpFile As HttpPostedFile = UP_FILE.PostedFile
Dim FileLength = 0
'记录文件长度变量
FileLength = UpFile.ContentLength
If FileLength <> 0 Then
Dim StreamObject As System.IO.Stream = UpFile.InputStream
'文件临时储存Byte数组
Dim FileByteArray(FileLength) As Byte
'读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2)
'读文件内容到FileByteArray数组
StreamObject.Read(FileByteArray, 0, FileLength)
If Trim(newdocbox1.Text) = "" Then
addnewMessage.Text = "文档编号不能为空"
Exit Sub
End If If Trim(newdocbox1.Text) = "" Then
addnewMessage.Text = "文档编号不能为空"
Exit Sub
End If If Trim(newdocbox3.Text) <> "" Then
If Not IsDate(Trim(newdocbox3.Text)) Then
addnewMessage.Text = "创建日期应该是日期"
Exit Sub
End If
End If StreamObject.Read(FileByteArray, 0, FileLength)
com2.Parameters.Add("@DocuID", SqlDbType.Char, 40).Value = newdocbox1.Text
com2.Parameters.Add("@DocuType", SqlDbType.Char, 40).Value = UpFile.ContentType
com2.Parameters.Add("@DocuName", SqlDbType.Char, 256).Value = File_name
com2.Parameters.Add("@DocuMen", SqlDbType.Char, 40).Value = newdocbox2.Text
com2.Parameters.Add("@DocuData", SqlDbType.DateTime, FileLength).Value = newdocbox3.Text
com2.Parameters.Add("@DocuDemo", SqlDbType.VarChar, 1000).Value = newdocbox4.Text
com2.Parameters.Add("@DocuCon", SqlDbType.Binary, FileLength).Value = FileByteArray Dim ada As New SqlClient.SqlDataAdapter("select * from 多文档信息表 where 文档编号='" & Trim(newdocbox1.Text) & "'", DeviceConnection)
Dim ds As New DataSet()
ada.Fill(ds, "beijian")
If ds.Tables(0).Rows.Count > 0 Then
addnewMessage.Text = "此文档编号已经存在了"
Exit Sub
End If
DeviceConnection.Open()
com2.ExecuteNonQuery()
DeviceConnection.Close() DocCloseLabel.Text = "添加成功"
DocAddPanel.Visible = False
DocClosePanel.Visible = True Else
addnewMessage.Text = "<p><b>请选择正确的文件</b>"
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try End Sub
End Class
strCon = "SERVER=yuankena;DATABASE=CRM;UID=sa;PWD=;"
Dim sqlcmd2 As New String("INSERT INTO dicUser(UserID, UserName, UserPwd, UserNOte,img) VALUES (@UserID, @UserName, @UserPwd, @UserNOte,@Img)")
Dim com2 As New SqlClient.SqlCommand(sqlcmd2, New SqlClient.SqlConnection(strCon))
'HttpPostedFile对象,用于读取图象文件属性
Dim UpFile As HttpPostedFile = txtImg.PostedFile
Dim FileLength = 0
'记录文件长度变量
FileLength = UpFile.ContentLength If FileLength <> 0 Then
Dim StreamObject As System.IO.Stream = UpFile.InputStream
'文件临时储存Byte数组
Dim FileByteArray(FileLength) As Byte
'读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
Dim x = UpFile.FileName.LastIndexOf("\"), File_name = Mid(UpFile.FileName, x + 2)
'读文件内容到FileByteArray数组
StreamObject.Read(FileByteArray, 0, FileLength)
StreamObject.Read(FileByteArray, 0, FileLength)
com2.Parameters.Add("@UserID", SqlDbType.NVarChar, 40).Value = txtUserID.Text
com2.Parameters.Add("@UserName", SqlDbType.NVarChar, 40).Value = txtUserName.Text
com2.Parameters.Add("@UserPwd", SqlDbType.NVarChar, 256).Value = txtUserPwd.Text
com2.Parameters.Add("@UserNOte", SqlDbType.NVarChar, 40).Value = txtUserNote.Text
com2.Parameters.Add("@Img", SqlDbType.Binary, FileLength).Value = FileByteArray
com2.Connection.Open()
com2.ExecuteNonQuery()
Else End If
Imports System.Data.SqlClient
Imports System.IO
Imports System.Xml
Public Class Doc_View_Detail
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
'查询数据库图像id
Dim ImgID = Request.QueryString("ImgID") Dim con As SqlClient.SqlConnection
'查询sql
Dim str = Context.GetConfig("appSettings")("dsn")
con = New SqlConnection(str)
Dim SqlCmd = "SELECT * from 多文档信息表 where 文档编号='" & ImgID & "'"
Try
con.Open() Dim ada As New SqlClient.SqlDataAdapter(SqlCmd, con)
Dim ds As New DataSet()
ada.Fill(ds, "wendang") '设定输出文件类型
'Response.AddHeader("Content-Disposition", "attachment; filename=" & ds.Tables(0).Rows(0).Item("文件名称"))
Response.ContentType = Trim(ds.Tables(0).Rows(0).Item("文档类型"))
'输出图象文件二进制数制
Dim FileByteArray() As Byte = ds.Tables(0).Rows(0).Item("文档内容")
Dim s = ds.Tables(0).Rows(0).Item("文档内容")
s = FileByteArray.Length
Response.OutputStream.Write(ds.Tables(0).Rows(0).Item("文档内容"), 0, CInt(s))
con.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End SubEnd Class