作者:Mr.XQIJIANG
出处: http://www.cnblogs.com/Mr-XQIJIANG/本文版权归【Mr.XQIJIANG】所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
/// <summary>
/// 删除图片数据时同时删除图片文件夹里面的相应图片文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string Aid = GridView1.DataKeys[e.RowIndex].Value.ToString();
//conn是web.config的链接字符串的name属性
string myConn = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection objConnection = new SqlConnection(myConn);
SqlCommand objCommand = new SqlCommand("select Aexhibition from EchibitionInfo where Aid=" + Aid, objConnection);
objConnection.Open();
SqlDataReader myreader = objCommand.ExecuteReader();
myreader.Read();
DataSet ds = new DataSet();
string pic = myreader["Aexhibition"].ToString();
string pic_link = Server.MapPath(Request.ApplicationPath) + "../BeForeWeb/Images/lg_img/" + pic;
if (System.IO.File.Exists(pic_link))
{
System.IO.File.Delete(pic_link);
}
myreader.Close();
objConnection.Close();
GridView1.DataBind();
}