上传文件

    技术2022-05-11  133

    参数说明FileBox:表单名称BasePath:文件基路径FileSize:文件大小LastError:错误信息Extension:文件扩展名FilePath:文件保存路径FileName:文件保存名称Name:文件原名称public static bool UploadMyFiles(System.Web.UI.HtmlControls.HtmlInputFile FileBox,string BasalPath,String SavePath,ref decimal FileSize,out string LastError,out String Extension ,out String FilePath,out String FileName,out string Name){DateTime datTime=System.DateTime.Now;String strTemp;string strFileName = FileBox.PostedFile.FileName;bool blnResult;LastError="";Name="";FilePath="";FileName="";Extension="";try{if (strFileName==""){LastError="请点击浏览选择要上传的文件!";return false;}if(Convert.ToDecimal(FileBox.PostedFile.ContentLength)<=FileSize*1048576){FileSize = FileBox.PostedFile.ContentLength/1024;CStat xStat = new CStat();xStat.UserID = System.Web.HttpContext.Current.Session["CurrentUserID"].ToString();if(xStat.Load()){bool sessionVIP;if(System.Web.HttpContext.Current.Session["BankVIP"] == null){sessionVIP = false;}else{sessionVIP = true;}if(xStat.FilesSize+FileSize>=Function.FeeOrFreeFile(sessionVIP)){System.Web.HttpContext.Current.Response.Redirect("~/blog/NotEnoughFile.htm");}}Name=Path.GetFileName(strFileName);Extension=Path.GetExtension(strFileName);Extension=Extension.ToLower();// if(true)//文件符合要求// {strTemp = datTime.ToShortDateString().Replace( "-", "");FileName = strTemp + datTime.ToLongTimeString().Replace(":","")+datTime.Millisecond+ Extension;FilePath = SavePath + strTemp + "/";CreateDirectory(BasalPath + FilePath);FileBox.PostedFile.SaveAs(BasalPath + FilePath + FileName);blnResult=true;}else{blnResult=false;LastError="上传的文件大小应在"+(FileSize).ToString()+"M以内!";}}catch (Exception ex){throw new System.Exception((ex.Message + ("/r/n" + ex.StackTrace)));}return blnResult;}


    最新回复(0)