前段时间一直在试验网站上传文件,失败N多,在借鉴各位牛人的blog资料之后,侥幸完成了上传文件的功能,不敢独享,现将代码贴显出来与各位分享!
string fullFileName = this.FileUp.PostedFile.FileName; //获取上传文件的全名
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //获取上传文件的类型
//判断文件的类型
if ((type == "jpg" || type == "jpeg" || type == "gif" || type == "png" || type == "swf" || type == "rar" || type == "zip") && FileUp.PostedFile.ContentLength < 2 * 1024 * 1024)
{
this.FileUp.PostedFile.SaveAs(Server.MapPath("../UpFiles/") + "\\" + fileName);
this.UploadPan.Visible = false;
this.UploadedPan.Visible = true;
this.CopyTxt.Value = "../UpFiles/" + fileName;
}
else
{
this.message.Text = "文件格式不正确/或者文件过大!";
}
string fullFileName = this.FileUp.PostedFile.FileName; //获取上传文件的全名
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //获取上传文件的类型 //判断文件的类型
if ((type == "jpg" || type == "jpeg" || type == "gif" || type == "png" || type == "swf" || type == "rar" || type == "zip") && FileUp.PostedFile.ContentLength < 2 * 1024 * 1024)
{
this.FileUp.PostedFile.SaveAs(Server.MapPath("../UpFiles/") + "\\" + fileName);
this.UploadPan.Visible = false;
this.UploadedPan.Visible = true;
this.CopyTxt.Value = "../UpFiles/" + fileName;
}
else
{
this.message.Text = "文件格式不正确/或者文件过大!";
}
浙公网安备 33010602011771号