引用命名空间 using System.IO;
try
{//服务器端地址
string Path = Server.MapPath("~/JiaoXueDaGang/updagang/");
//需要删除的具体的路径和文件
string serverPath = Path + name;
FileInfo fil = new FileInfo(serverPath);
//判断文件是否存在
if (fil.Exists)
{
//删除
fil.Delete();
}
//删除数据库中的记录
string sql = "delete from JiaoXueDaGang where zid ='" + id + "'";int i = SqlHelper.ExecuteNonQuery(Conn.ConnString, CommandType.Text, sql);
if (i > 0)
{ }
else
{
HttpContext.Current.Response.Write("<script>alert('删除失败!');history.back(-1);</script>");
return;
}
}
catch (Exception ex)
{
MessageBox.alert(Page, ex.Message.ToString());
}