.NET 历遍删除文件

今天写历遍删除文件居然忘记怎么写了  晕倒  以后要多看书加强记忆.........

        string Paths = Server.MapPath("rent_pic/");
        DirectoryInfo Di = new DirectoryInfo(Paths);

        try
        {
            for (int i = 0; i < GVinfo.Rows.Count; i++)
            {
                Label Lid = (Label)GVinfo.Rows[i].FindControl("Lid");
                CheckBox Cb = (CheckBox)GVinfo.Rows[i].FindControl("CheckBox");
                if (Cb.Checked)
                {
                    house_secondhand.House_Rent_Delete(Convert.ToInt32(Lid.Text), Request.Cookies["member"].Value);
                    foreach (FileInfo F in Di.GetFiles())
                    {
                        try
                        {
                            int Position = F.Name.IndexOf("-");
                            if (F.Name.Substring(0, Position) == Lid.Text)
                            {
                                File.Delete(Di + F.Name);
                            }
                        }
                        catch
                        {

                        }
                    }

                }
            }
            Bind();
        }
        catch
        {
            Page.RegisterStartupScript("", "<script>alert('删除失败!');</script>");
        }

 

写个文章Mark一下 忘记的时候可以看一下......

你可能感兴趣的:(.net)