上传文件

 上传文件   


参数说明
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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值