谢谢
public void pic()
{
string dirPath;
dirPath = Server.MapPath("upfile");
DirectoryInfo adminDir = new DirectoryInfo(dirPath);
foreach (FileInfo del in adminDir.GetFiles())
{
if (del.Extension.ToLower() == ".jpg" || del.Extension.ToLower() == ".gif" || del.Extension.ToLower() == ".png")
{
Session["abc"] = del;
Response.Write(Session["abc"]);
SqlConnection conn = Class1.DB();
conn.Open();
SqlCommand cmd1 = new SqlCommand("select count(*) from
new1 where picpath='" + Session["picpath"] + "'", conn);
int pic1 = Convert.ToInt32(cmd1.ExecuteScalar());
conn.Close();
if (pic1>0)
{
Response.Write("数据存在");
}
else
{
del.Delete();
}
}
}
}
我这样写了是可以删除 我刷新页面的时候 文件夹里图片全没了
if (!IsPostBack)
{
pic();
}