asp.net下文件上傳和文件刪除的代碼
來源:懂視網
責編:小采
時間:2020-11-27 22:45:25
asp.net下文件上傳和文件刪除的代碼
asp.net下文件上傳和文件刪除的代碼:文件上傳 HttpPostedFile postFile = Request.Files[imgFile]; if(postFile.FileName!=String.Empty){ ex=postFile.FileName.Substring(postFile.FileName.LastIndexOf(.)); fileName= Date
導讀asp.net下文件上傳和文件刪除的代碼:文件上傳 HttpPostedFile postFile = Request.Files[imgFile]; if(postFile.FileName!=String.Empty){ ex=postFile.FileName.Substring(postFile.FileName.LastIndexOf(.)); fileName= Date

文件上傳
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); //刪除文件,別忘了檢查一下有沒有這個文件
}
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
asp.net下文件上傳和文件刪除的代碼
asp.net下文件上傳和文件刪除的代碼:文件上傳 HttpPostedFile postFile = Request.Files[imgFile]; if(postFile.FileName!=String.Empty){ ex=postFile.FileName.Substring(postFile.FileName.LastIndexOf(.)); fileName= Date