private void Button1_Click(object sender, System.EventArgs e)
{
string fullfilename=this.File1.PostedFile.FileName;//上传的文件名
string size=this.file1.postedFile.ContentLength.ToString();//获取文件的大小
string filename=fullfilename.Substring(fullfilename.LastIndexOf("\\")//获得文件的+1);
string type=fullfilename.Substring(fullfilename.LastIndexOf(".")+1);//得到文件的后缀名
if (type=="jpg"||type=="bmp"||type=="gif"||type=="ico")
{
this.File1.PostedFile.SaveAs(Server.MapPath("upload")+"\\"+filename);
this.Imp.Visible=true;
this.Imp.ImageUrl="upload/"+filename;
}
else
{
Response.Write("<script language=''javascript''>alert(''你上传的图片格式有错误!'')</script>");
}
} |