File Upload
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); // upload a file and check whether a Directory is created.
PostFile. SaveAs (absPath + fileName );
}
File Deletion
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); // Delete the File. Do not forget to check whether the File Exists.
}