MEmory stream, file stream

P

Pums

While retriving an image i came across two streams
Filestream and Memorystream. can anyone guide me when
should i use which?
 
J

Jon Skeet [C# MVP]

Pums said:
While retriving an image i came across two streams
Filestream and Memorystream. can anyone guide me when
should i use which?

Well, what exactly do you want to do? A FileStream reads/writes from/to
a file; a MemoryStream reads/writes from/to memory.
 
P

Pums

Actually i am retriving an image from sql server. It's in
binary. i want to assign that image to a picturebox. now
for that i can create write that binary as a byte stream
in memory stream or i can create a temporary file by
using filestream. Sometimes u might now have writable
permisssion to a folder. in that case you can't create
that file by using filestream.

So, my point was to exactly know the scenerio where we
should use filestream or memorystream only. Right now for
my application i can use both. but, there may be cases
where i need to use any one of them. I wanted to know
those cases.
 
J

Jon Skeet [C# MVP]

Pums said:
Actually i am retriving an image from sql server. It's in
binary. i want to assign that image to a picturebox. now
for that i can create write that binary as a byte stream
in memory stream or i can create a temporary file by
using filestream. Sometimes u might now have writable
permisssion to a folder. in that case you can't create
that file by using filestream.

So, my point was to exactly know the scenerio where we
should use filestream or memorystream only. Right now for
my application i can use both. but, there may be cases
where i need to use any one of them. I wanted to know
those cases.

I would personally go for a MemoryStream here - I can't see that using
a FileStream buys you anything, really. In terms of cases where you
need to use one in particular - if you don't want a file involved, use
a MemoryStream, and if you do, use a FileStream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top