In my projects, I have a helper class called TempFile. It has several static methods that I use to write a stream (or an array of bytes if need be) to a temporary file. Here's a simplified example of such a method:
public static string Write(Stream stream)
{
string FileName = Path.GetTempFileName();
// Write the contents of stream to a file with FileName
return FileName;
}
Then, I have another method that accepts a file path for later deletion which is a member of my 'parsing' class, although you could put it in its own static helper class:
public string ForDeletion(string path)
{
ListOfPaths.Add(path);
return path;
}
Finally, I do the following:
SomeApiFunction(ForDeletion(TempFile.Write(myStream)));
This is the best way I've come up with for circumventing an API's lack of stream handling capabilities.