加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net下文件上传和文件删除的代码

发布时间:2020-12-15 20:45:39 所属栏目:asp.Net 来源:网络整理
导读:文件上传 HttpPostedFilepostFile=Request.Files["imgFile"]; if(postFile.FileName!=String.Empty){ ex=postFile.FileName.Substring(postFile.FileName.LastIndexOf(".")); fileName=DateTime.Now.ToString("yyyyMMdd")+ex; absPath=System.Web.HttpContext
文件上传
HttpPostedFile postFile = Request.Files["imgFile"];
if(postFile.FileName!=String.Empty){
       ex=postFile.FileName.Substring(postFile.FileName.LastIndexOf("."));
       fileName= DateTime.Now.ToString("yyyyMMdd") + ex;
       absPath=System.Web.HttpContext.Current.Server.MapPath("/img_ad/"+adTypeEn+"/";);

      if(!System.IO.Directory.Exists(absPath)) System.IO.Directory.CreateDirectory(absPath);   //上传文件,要检查一下是否建立了相关目录
      postFile.SaveAs(absPath+fileName);
}


文件删除
string sqlFile="select ('/img_ad/'+Ltrim(Rtrim(compName))+'/'+Ltrim(Rtrim(fileName)))as adFile from adinfo where id="+sid;
object objAd=SqlComd.CreateSqlScalar(sqlFile);
 if(objAd!=null){
       string fName = Server.MapPath(objAd.ToString());
       if(File.Exists(fName)) File.Delete(fName);     //删除文件,别忘了检查一下有没有这个文件
 } 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读