前台
<%@ 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 ></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();
  }
 }
}


相关文章:

  • 2021-08-17
  • 2022-01-10
  • 2021-05-25
  • 2021-06-26
  • 2021-12-04
  • 2021-07-26
  • 2022-01-20
猜你喜欢
  • 2022-01-28
  • 2022-12-23
  • 2021-12-12
  • 2022-01-07
  • 2021-05-20
  • 2022-01-18
  • 2021-11-04
相关资源
相似解决方案