Dispose Returned stream in WCF

In this below method I have returned a file stream for downloading it in client or browser. Before returning that stream i have keep that file in a temporary location.After return that stream i have to dispose it and delete that directory.

public Stream DownloadAttachment()
Stream stream = null;
var directoryInformation = CommonServices.Utility.DirectoryHelper.GetTempFolderRootLocation();
string newFolderPath = "C:\\Attachments\\" + Guid.NewGuid();

string fullPath = newFolderPath + "\\" + fileName;
stream = File.OpenRead(fullPath);

catch (Exception exception)

return null;
OperationContext clientContext = OperationContext.Current;
clientContext.OperationCompleted += (sender, args) =>
if (stream != null)
Directory.Delete(newFolderPath, true);
return stream;

Enjoy Coding…