⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filenew.aspx.cs

📁 asp.net 办公自动化系统 人事管理 公文管理 内部邮件管理以及办公自动化系统中不可或缺的模块
💻 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 System.Configuration;
using System.IO;

namespace eOA
{
	/// <summary>
	/// filenew 的摘要说明。
	/// </summary>
	public class filenew : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button Button4;
		protected System.Web.UI.WebControls.Button Button6;
		protected System.Web.UI.WebControls.TextBox txtContent;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.TextBox txtSubject;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label lbl;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.HtmlControls.HtmlInputFile txtFile;
		protected System.Web.UI.WebControls.TextBox txtSend;
		protected System.Web.UI.WebControls.TextBox txtRecv;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;

		string strFileName;
		string strVirtualPath;
		string strLocalPath;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			txtSend.Text=Convert.ToString(Session["UserName"]);
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button6.Click += new System.EventHandler(this.Button6_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		public void Button6_Click(object sender, System.EventArgs e)
		{
			if(txtFile.Size !=0)
			{
				if(BindFile(txtFile.Value.ToString())==1)
				{
					//txtFile.Value=strVirtualPath;
					if (txtSubject.Text.ToString()!="" & txtContent.Text.ToString()!="")
					{
						DateTime cd = new DateTime();
						cd = DateTime.Now;
						File myFile=new File();
						myFile.AddFile(txtSubject.Text,txtContent.Text,strVirtualPath,myFile.GetEmpIDByName(txtSend.Text),txtSend.Text,myFile.GetEmpIDByName(txtRecv.Text),txtRecv.Text,cd,"未处理");
						lbl.Text="发送成功!";
					}
					txtFile.Size=0;
					
					//Response.Redirect("ArticleShow.aspx");
				}
				else if(BindFile(txtFile.Value.ToString())==0)
				{
					lbl.Text="您上传的文件名已经存在,请重新命名.";
				}
				else if(BindFile(txtFile.Value.ToString())==-1)
				{
					lbl.Text="文件上传失败!";
				}
			}
			
		}


		int BindFile(string sFileName)
		{
			
			int i = sFileName.LastIndexOf("\\"); // 从文件的地址中找到文件名开始前的位置
			string sFile=sFileName.Substring(i+1); //取出文件名

			if (System.IO.File.Exists(ConfigurationSettings.AppSettings["strLocalPath"]+sFile))
			{				
				return 0;
			}
			else
			{
				try
				{
					// 上传文件
					txtFile.PostedFile.SaveAs(ConfigurationSettings.AppSettings["strLocalPath"]+sFile);		
					strFileName=sFile;
					strLocalPath=ConfigurationSettings.AppSettings["strLocalPath"]+sFile;
					strVirtualPath=ConfigurationSettings.AppSettings["strVirtualPath"]+sFile;
					return 1;
				}
				catch
				{					
					return -1;
				}
			}

		}
	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -