1
{
2
string fullFileName=this.File1.PostedFile.FileName;//获得文件全路径
3
string fileName=fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);//获取文件名
4
string type=fullFileName.Substring (fullFileName.LastIndexOf(".")+1); //取得文件后缀名
5
if(type=="jpg"||type=="gif"||type=="bmp")
6
{
7
this.File1.PostedFile.SaveAs(Server.MapPath("up")+"\\"+fileName);
8
this.Image1.Visible=true;
9
this.Image1.ImageUrl="up/"+fileName;
10
}
11
else
12
{
13
Response.Write("<script language='javascript'>alert('你选择的图片格式错误');</script>");
14
}
15
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15
