Advance Of The Face

----学到得越多,却发现自己越无知!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

判断上传文件格式和容量的C#代码

Posted on 2007-09-10 09:07  Season-LMZ  阅读(1411)  评论(3)    收藏  举报
    前段时间一直在试验网站上传文件,失败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 = "文件格式不正确/或者文件过大!"
}