//判断是否选择文件
if (!FileUpload1.HasFile)
{
Response.Write("没有要上传的文件!");
return;
}
string filepath = FileUpload1.PostedFile.FileName;
int i = filepath.IndexOf(".");
string fileType = filepath.Substring(i);
string[] extens = new string[] { ".jpeg", ".bmp", ".png", ".gif", ".jpg" };
string filename = FileUpload1.FileName;
if (extens.Contains(fileType))//格式
{
string path = HttpContext.Current.Server.MapPath("~/UploadFiles/");
FileUpload1.PostedFile.SaveAs(path+filename);
}
else
{
Response.Write("文件格式不正确!");
return;
}