asp.net文件删除

 private ArrayList posted;

 posted = new ArrayList();

  foreach (Attachment item in NewsService.getList(newsID))
        {
            filePath = Server.MapPath("~/Attachment/" + item.Name);
            posted.Add(filePath);
        }

Delete()

private void Delete()
    {
        foreach (var item in posted)
        {
            try
            {
                if (System.IO.File.Exists(item.ToString()))
                {
                    System.IO.File.Delete(item.ToString());
                }
            }
            catch (Exception ex)
            {

                Response.Write("<br>" + ex.Message);
            }
        }
    }

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