How to open a file from Memory Stream
Solution 1
It depends on the client :) if the client will accept input from stdin you could push the dta to the client. Another possibility might be to write a named-pipes server or a socket-server - not trivial, but it may work.
However, the simplest option is to just grab a temp file and write to that (and delete afterwards).
var file = Path.GetTempFileName();
using(var fileStream = File.OpenWrite(file))
{
var buffer = memStream.GetBuffer();
fileStream.Write(buffer, 0, (int)memStream.Length);
}
Remember to clean up the file when you are done.
Solution 2
Path.GetTempFileName() returns file name with '.tmp' extension, therefore you cant't use Process.Start() that needs windows file association via extension.
James
Updated on January 07, 2020Comments
-
James over 4 years
Is it possible to open a file directly from a
MemoryStream
opposed to writing to disk and doingProcess.Start()
? Specifically a pdf file? If not, I guess I need to write theMemoryStream
to disk (which is kind of annoying). Could someone then point me to a resource about how to write aMemoryStream
to Disk?-
Marc Gravell almost 13 years(James - I removed the 4.0 dependency from my answer)
-
-
Magnus almost 13 yearsOr use
WriteTo
(for non 4.0) -
Marc Gravell almost 13 years@Magnus - I removed that; realised that I can use the back-buffer from MemoryStream