How can I serve a dynamic file, and then clean it up?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmFzb24gQmFybmV0dA==?=

    How can I serve a dynamic file, and then clean it up?

    I wrote an aspx page that creates a .pdf file upon request and transfers the
    file to the client for viewing (via an Adobe Acrobat plug-in). Afterwards,
    the file is no longer needed and should be deleted from the server. Here is
    a code snippet as an example:

    Response.Conten tType = "applicatio n/pdf";
    Response.Clear( );
    Response.Transm itFile(filename );
    Response.Flush( );
    //Response.End();
    System.IO.File. Delete(filename );

    Could someone suggest a better way of getting the dynamic file to the client
    while maintaining a clean server?
  • IanL

    #2
    Re: How can I serve a dynamic file, and then clean it up?

    Instead of writing to the file to disk, you would use a memory stream.
    Then transfer the binary data into a byte array, and use the Response
    object to output it to the client.
    Instead of using Response.Transm itFile use:

    Response.Binary Write(Temporary FileByteArray);

    DotCodeDump: http://www.dotcodedump.com

    +Ian Lintner

    Comment

    • =?Utf-8?B?SmFzb24gQmFybmV0dA==?=

      #3
      Re: How can I serve a dynamic file, and then clean it up?

      I'm actually using a 3rd party tool that generates the file. I have no
      control over that. However, your suggestion helped me load the file into a
      byte array, delete the file, and then write the binary data to the client.
      Thanks!

      "IanL" wrote:
      Instead of writing to the file to disk, you would use a memory stream.
      Then transfer the binary data into a byte array, and use the Response
      object to output it to the client.
      Instead of using Response.Transm itFile use:
      >
      Response.Binary Write(Temporary FileByteArray);
      >
      DotCodeDump: http://www.dotcodedump.com
      >
      +Ian Lintner
      >

      Comment

      Working...