Sunday, November 14, 2004

Deleting a SOAP attachment file

If you're creating a SOAP attachment on the server, and creating a temporary file for the purpose, you probably need to delete the file after you're done. You can't do this in ANY of the events provided - the attachment stream is not freed before any event occurs. So, what you must do is that instead of using TSOAPAttachment.SetSourceFile, you must use TSOAPAttachment.SetSourceStream instead, but with your own stream like so:


type
TMyStream = class( TFileStream )
public
destructor Destroy; override;
end;
...
destructor TMyStream.Destroy;
begin
inherited;
Deletefile('c:\sql1.txt'); // or whatever has to be deleted
end;


and in your implementation have something like this:


var str : TMYStream;
begin
Result := TSOAPAttachment.Create;
Str := TMyStream.Create('c:\sql1.txt', fmOPenread);

Result.SetSourceStream(Str,soOwned) ;
end;

0 Comments:

Post a Comment

<< Home