Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey
I want to know if can read or open a file a any steam without writing a file to the disc. This is what i have done so far.
C#
byte[] MyData = new byte[0]; //*this is my byte array. i wll get my bytes from my database,name,ect*// 
  MemoryStream stream = new MemoryStream(MyData); //now i have mydata in stream

from here i don't know to go on.All i need to know is how to open the file form the stream.
please i will really thank you for the help.


i also tried
C#
FileStream fs2= null;
         FileStream fs = new FileStream(@"C:\sd.txt",FileMode.Open);
         byte[] data = new byte[fs.Length];
         fs.Read(data,0,(int)fs.Length);

         fs2.Read(data,0,(int)fs.Length);
         fs.Close();

         System.Diagnostics.Process.Start(fs2.Name);
Posted
Updated 19-Aug-12 12:03pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Aug-12 20:19pm    
What could it possibly mean: "open a file from the stream". What is the direction of moving data you need?
--SA

You can't. It's in a stream, you can't do anything with it, apart from write it somewhere, or store it for your use. Windows can't open a program that is not on the hard drive, when it's in that pure binary form. You're just writing code at random, trying to do something impossible.
 
Share this answer
 
You can not create a new process from a stream. It can only be launched from a file on disk.
 
Share this answer
 
What are you trying to do ?

FileStream is nothing but exposing a stream around the file. Also if you have a filestream you use it for
1. Byte level operations like encryption decryption.
2. Compress it using standard or custom deflator(zip, rar).
3. If you know the file format, then you can use Filestream to read its header(its fixed length information about the file, how data is packed on it etc). Headers are present for most of the files like JPEG, BMP etc.
 
Share this answer
 
When your file type is Image, it is possible. Like below codes:

C#
string fileName = "D:\\image.png";
byte[] buffer = File.ReadAllByte(fileName);
Stram stream = new MemoryStream(buffer);
this.PictureBox.Image = Image.FromStream(stream);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900