前臺
<%@ Page language="c#" Codebehind="ZJSJKSC.aspx.cs" AutoEventWireup="false" Inherits="DDTYDB.Module.WJGL.ZJSJKSC" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
?<HEAD>
??<title>ZJSJKSC</title>
??<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
??<meta content="C#" name="CODE_LANGUAGE">
??<meta content="JavaScript" name="vs_defaultClientScript">
??<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
??<script language="javascript">
???function CheckFileNameLen(s,e)
???{
????var strFullName = document.all.fileZJSJ.value;
????if(strFullName == null || strFullName == "")
????{
?????alert("請選擇上傳的文件");
?????return false;
????}
????else
????{
?????var lastIndex = strFullName.lastIndexOf("\\");
?????strName = strFullName.substring(lastIndex,strFullName.length-1);
?????var strResult = strName.replace(/[^\x00-\xff]/g,"aa");
?????if(strResult.length > 100)
?????{
??????
??????alert("文件名過長");
??????return false;
?????}
?????else
?????{
??????return true;
?????}
????}
???}
???
??</script>
?</HEAD>
?<body>
??<form id="form1" method="post" encType="multipart/form-data" runat="server">
???<TABLE id="Table10" cellSpacing="0" cellPadding="0" width="100%" border="0" frame="border">
????<TR vAlign="middle" width="100%">
?????<TD style="HEIGHT: 26px" vAlign="top">
?????<TD class="GbText" style="HEIGHT: 26px" align="right" width="2%" background="../../Images/treetopbg.jpg"
??????bgColor="#c0d9e6"><FONT color="#003366" size="3"><IMG height="18" src="../../Images/Role.gif" width="18"><STRONG>
???????</STRONG></FONT>
?????</TD>
?????<TD class="GbText" style="HEIGHT: 26px" noWrap align="left" width="13%" background="../../Images/treetopbg.jpg"
??????bgColor="#e8f4ff"><STRONG> <FONT face="宋體" color="#003399">最佳實踐資料上傳</FONT></STRONG>
?????</TD>
?????<TD class="GbText" style="HEIGHT: 26px" align="right" width="35%" background="../../Images/treetopbg.jpg"
??????bgColor="#e8f4ff"><FONT face="宋體"></FONT></TD>
?????</TD>
?????<TD class="GbText" style="HEIGHT: 26px" vAlign="bottom" align="right" width="12%" background="../../Images/treetopbg.jpg"
??????bgColor="#e8f4ff"><FONT face="宋體"></FONT></TD>
?????</TD>
?????<TD class="GbText" style="HEIGHT: 26px" vAlign="bottom" align="left" width="38%" background="../../Images/treetopbg.jpg"
??????bgColor="#e8f4ff"> </TD>
?????</TD></TR>
???</TABLE>
???<HR color="#006699">
???<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
????<TR>
?????<TD align="left" width="100%" colSpan="2"><asp:datagrid id="dgUserInfo" runat="server" Width="100%" DataKeyField="ZLBH" AutoGenerateColumns="False"
???????AllowPaging="True" BorderColor="#93BEE2" BorderWidth="1px" CellPadding="3">
???????<SelectedItemStyle BackColor="LightSteelBlue"></SelectedItemStyle>
???????<AlternatingItemStyle BackColor="#E8F4FF"></AlternatingItemStyle>
???????<ItemStyle Font-Size="9pt" HorizontalAlign="Center"></ItemStyle>
???????<HeaderStyle Font-Size="9pt" HorizontalAlign="Center" Height="20px" ForeColor="White" BackColor="#337FB2"></HeaderStyle>
???????<Columns>
????????<asp:ButtonColumn DataTextField="WJMC" HeaderText="文檔名稱" CommandName="select"></asp:ButtonColumn>
????????<asp:BoundColumn DataField="FBSJ" HeaderText="發布時間"></asp:BoundColumn>
???????</Columns>
???????<PagerStyle HorizontalAlign="Right" BackColor="#E8F4FF" Mode="NumericPages"></PagerStyle>
??????</asp:datagrid></TD>
????</TR>
????<TR>
?????<TD align="center" width="100%" colSpan="2" height="50"> </TD>
????</TR>
????<tr>
?????<td align="center" colSpan="2"><asp:panel id="panConter" runat="server" Width="100%">
???????<TABLE width="100%" align="center">
????????<TR>
?????????<TD align="right" width="40%" bgColor="#e8f4ff"><FONT class="FontCss" face="宋體">文件:</FONT></TD>
?????????<TD bgColor="#e8f4ff"><FONT face="宋體"><INPUT id="fileZJSJ" type="file" size="50" name="UploadFile" runat="server"><BR>
??????????</FONT>
?????????</TD>
????????</TR>
????????<TR>
?????????<TD vAlign="middle" align="center" bgColor="#e8f4ff" colSpan="2" height="40"><FONT class="fontcss" face="宋體">
???????????<asp:button id="btnUpLoad" runat="server" Width="70px" CssClass="buttoncss" Text="立即上傳"></asp:button>
??????????</FONT>
?????????</TD>
????????</TR>
???????</TABLE>
??????</asp:panel></td>
????</tr>
???</TABLE>
???<asp:Label id="labInfo" runat="server" Width="100%"></asp:Label>
??</form>
?</body>
</HTML>
后臺cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using JySoft.TYDB.BLL;
using JySoft.TYDB.Model;
namespace DDTYDB.Module.WJGL
{
?/// <summary>
?/// ZJSJKSC 的摘要說明。
?/// </summary>
?public class ZJSJKSC : System.Web.UI.Page
?{
??protected System.Web.UI.WebControls.DataGrid dgUserInfo;
??protected System.Web.UI.WebControls.Panel panConter;
??protected System.Web.UI.WebControls.Label labInfo;
??protected System.Web.UI.HtmlControls.HtmlInputFile fileZJSJ;
??protected System.Web.UI.WebControls.Button btnUpLoad;
??private int m_UserID = 0;
?
??private void Page_Load(object sender, System.EventArgs e)
??{
???this.btnUpLoad.Attributes.Add("onclick","javascript: return CheckFileNameLen()");
???// 在此處放置用戶代碼以初始化頁面
???if(Session["User"] == null)
???{
????Session["ERR"]="Session過期,請重新登陸!";
????Response.Redirect("../err.aspx");
????return;???
???}
???if(!Page.IsPostBack)
???{
????BindData();
???}
??}
??/// <summary>
??/// 綁定數據
??/// </summary>
??public void BindData()
??{
???try
???{
????DocumentManageBLL bll = new DocumentManageBLL();
????DocumentModelCollection collection = bll.GetZJSJ();
????dgUserInfo.DataSource = collection;
????dgUserInfo.DataBind();
???}
???catch(Exception ex)
???{
????labInfo.Text = ex.Message;
???}
??}
??#region Web 窗體設計器生成的代碼
??override protected void OnInit(EventArgs e)
??{
???//
???// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
???//
???InitializeComponent();
???base.OnInit(e);
??}
??
??/// <summary>
??/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
??/// 此方法的內容。
??/// </summary>
??private void InitializeComponent()
??{???
???this.btnUpLoad.Click += new System.EventHandler(this.Button1_Click);
???this.Load += new System.EventHandler(this.Page_Load);
??}
??#endregion
??private void Button1_Click(object sender, System.EventArgs e)
??{
???if(fileZJSJ.PostedFile.ContentLength <= 0)
???{
????return;
???}
???else
???{
????byte[] filebytes = new byte[fileZJSJ.PostedFile.ContentLength];
????fileZJSJ.PostedFile.InputStream.Read(filebytes,0,fileZJSJ.PostedFile.ContentLength);
????//文件名
????string strFullFileName = fileZJSJ.Value;
????//strFullFileName = strFullFileName.(@"\r\n"),;
????string strWJMC = strFullFileName.Substring(strFullFileName.LastIndexOf("\\") + 1);
????if(Session["User"] != null)
????{
?????UserInfo m_UserInfo = Session["User"] as UserInfo;
?????m_UserID = m_UserInfo.YHID;
????}
????
????DocumentManageBLL bll = new DocumentManageBLL();
????bll.UpLoadZJSJFile(strWJMC,this.m_UserID,DateTime.Now,filebytes);
???}
???BindData();
??}
?}
}