System.IO.File.Delete("file path");

解决方案 »

  1.   

    /// <summary>
    /// 删除过期的图表文件。
    /// </summary>
    private void ClearDateOutImg()
    {
    //先取得Chart文件夹中的文件列表
    string[] fileEntries = System.IO.Directory.GetFiles(this.Page.Server.MapPath("Chart"));

    foreach(string singFiles in fileEntries)//遍历文件列表
    {
    //将文件的生成日期与系统日期相比,如果是当日以前生成的文件,删除它
    if(System.DateTime.Compare(System.IO.File.GetCreationTime(singFiles).AddDays(1),System.DateTime.Now) < 0)
    {
    System.IO.File.Delete(singFiles);
    }
    }
    }