📄 image.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Text.RegularExpressions;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace Web_Exam
{
/// <summary>
/// image 的摘要说明。
/// </summary>
public class image : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile UploadFile;
protected System.Web.UI.HtmlControls.HtmlInputButton cmdOK;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
if(Session["userRole"]==null)
{
Response.Write("<script>top.location.href='ManagerLogin.aspx';</script>");
return;
}
string userRole="";
if(!Page.IsPostBack)
{
userRole=Session["userRole"].ToString().Trim();
if(userRole=="1")
{
}
else
{
Page.Visible=false;
}
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.cmdOK.ServerClick += new System.EventHandler(this.cmdOK_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdOK_ServerClick(object sender, System.EventArgs e)
{
int num=0;
if (UploadFile.PostedFile.ContentType!="image/pjpeg" && UploadFile.PostedFile.ContentType!="image/bmp" && UploadFile.PostedFile.ContentType!="image/gif")
{
Response.Write("<script language=javascript>alert('对不起,目前本系统只支持jpg,bmp,gif三种格式的图形!')</script>");
return;
}
string baseLocation = Server.MapPath("../../Exam_Image/"+Session["userId"].ToString().Trim()+"/"); // 上传路径
if(!System.IO.Directory.Exists(baseLocation))
{
System.IO.Directory.CreateDirectory(baseLocation);
}
string fn = System.IO.Path.GetFileName(UploadFile.PostedFile.FileName);
int tmp=fn.LastIndexOf('.');
string Suffix=fn.Substring(tmp);
string FullName=baseLocation+num+Suffix;
while(System.IO.File.Exists(FullName))
{
num++;
FullName=baseLocation+num+Suffix;
}
UploadFile.PostedFile.SaveAs(FullName);
string script="<script language=javascript>image('"+"../Exam_Image/"+Session["userId"].ToString().Trim()+"/"+num+Suffix+"');</script>" ;
Page.RegisterStartupScript("test",script);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -