HttpFileCollection and HttpPostedFile

J

Jennifer Mathews

I realize I can use

Dim hpf As HttpPostedFile
hpf.SaveAs("c:\whereever\filename.xxx) to save a file.

But I need to pass the hpf.InputStream to a class and save the file from there.
So all I do is need to pass a System.IO.Stream to it with hpf.InputStream .

Once that is passed, how do I know how to save contents of hpf.InputStream ?

Do I do a Binary Write or a regular Text Write?

Thanks
 
G

Gregory A. Beamer

I realize I can use

Dim hpf As HttpPostedFile
hpf.SaveAs("c:\whereever\filename.xxx) to save a file.

But I need to pass the hpf.InputStream to a class and save the file
from there. So all I do is need to pass a System.IO.Stream to it with
hpf.InputStream .

Once that is passed, how do I know how to save contents of
hpf.InputStream ?

Do I do a Binary Write or a regular Text Write?


This depends on the content of what you are saving. If the file is an
image, a text write can end up saving the bytes as characters and not
bytes. Then you can read the file anytime you want, but not as a
picture. :)

If you have the extension, you should be able to determine the file
type. If not, you can examine the stream and see if there is some
information about the file. Graphics files, for example, have headers
(find the first null char [ (char) 0 ] and the bits before it are the
header). You can read into a buffer until you hit the null char and then
read the header. If there is no header, I would assume a text file.

Peace and Grace,
Greg


--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
J

Jennifer Mathews

Thanks Greg. That got me going in the right direction.

Gregory A. Beamer said:
I realize I can use

Dim hpf As HttpPostedFile
hpf.SaveAs("c:\whereever\filename.xxx) to save a file.

But I need to pass the hpf.InputStream to a class and save the file
from there. So all I do is need to pass a System.IO.Stream to it with
hpf.InputStream .

Once that is passed, how do I know how to save contents of
hpf.InputStream ?

Do I do a Binary Write or a regular Text Write?


This depends on the content of what you are saving. If the file is an
image, a text write can end up saving the bytes as characters and not
bytes. Then you can read the file anytime you want, but not as a
picture. :)

If you have the extension, you should be able to determine the file
type. If not, you can examine the stream and see if there is some
information about the file. Graphics files, for example, have headers
(find the first null char [ (char) 0 ] and the bits before it are the
header). You can read into a buffer until you hit the null char and then
read the header. If there is no header, I would assume a text file.

Peace and Grace,
Greg


--
Vote for Miranda's Christmas Story
http://tinyurl.com/mirandabelieve

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top