protected void gvUploadFiles_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Delete") { try { string StoredFileName = e.CommandArgument.ToString(); BEStudent objBEStudent = new BEStudent(); BStudent objBStudent = new BStudent(); objBEStudent.IntTransID = Convert.ToInt64(Request.QueryString["TransID"]); objBEStudent.strOriginalFileName = StoredFileName; System.IO.FileInfo objFileName = new System.IO.FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["StudentUploads"]) + "\\" + StoredFileName); if (objFileName.Exists) { objFileName.Delete(); objBStudent.BStudentDeleteUploadedFile(objBEStudent); } else { //ScriptManager.RegisterStartupScript(this, this.GetType(), "NotSaved", "alert('File doesnot exist');", true); Page.ClientScript.RegisterStartupScript(GetType(), "MyScript", "alert('File deletion failed.Please try again.');", true); } gvUploadFiles.Rebind(); trMessage.Visible = false; } catch (Exception) { } } }