我在系统(基于Web的程序)中,用户在画面上点击一个按钮的时候,会在server端导出一个文本文件并传递到客户端。  
 
导出后,如何删除这个临时文件?  
 
如果不删除的话,将来在服务端,会生成大批的垃圾文件,大量占用系统的资源。  
 
希望高手指点。

解决方案 »

  1.   

    你可以直接用流的方式写入,从而避免产生临时文件,例如用一个单独的aspx来生成文件数据流,
    参看
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    Bitmap bitGraph = new Bitmap( 100, 100 );
    Graphics gImage = Graphics.FromImage( bitGraph );
    gImage.FillRectangle( new SolidBrush( Color.Violet ), 0,0, 100, 100 ); MemoryStream ms = new MemoryStream();
    bitGraph.Save( ms, System.Drawing.Imaging.ImageFormat.Jpeg );
    ms.Flush();
    byte[] bData = ms.GetBuffer();
    ms.Close(); try
    { Response.ContentType = "application/x-www-form-urlencoded";
    Response.BinaryWrite( bData );
    }
    catch(Exception Error)
    {
    Response.Write(Error.Message);
    }   
    }