I am storing attachments in my applications.
These gets stored in SQL as varbinary
types.
I then read them into byte[]
object.
I now need to open these files but dont want to first write the files to disk and then open using Process.Start()
.
I would like to open using inmemory streams. Is there a way to to this in .net. Please note these files can be of any type
Using File. The static File class in the System.IO namespace provides a simple static method WriteAllBytes() that we can use to write all the data from a byte array to a file. => File. WriteAllBytes(filePath, data); public static void SaveByteArrayToFileWithStaticMethod(byte[] data, string filePath) => File.
In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.
You can write all bytes to file without using Streams:
System.IO.File.WriteAllBytes(path, bytes);
And then just use
Process.Start(path);
Trying to open file from memory isn't worth the result. Really, you don't want to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With