System.Web Namespace HttpPostedFile Class
Gets a Stream object which points to an uploaded file to prepare for reading the contents of the file.
[ VB ]
Public ReadOnly Property InputStream As Stream
[ C# ]
public Stream InputStream {get;}
[ C++ ]
public: __property Stream* get_InputStream ( );
[ JScript ]
public function get InputStream ( ) : Stream;
A Stream pointing to a file.
The following example reads the contents of the first file in the client's file collection into a byte array and copies the byte array to a string.
[ VB ]
Dim myFileCollection As HttpFileCollection
Dim myFile As HttpPostedFile
Dim FileLen As Integer
Dim MyString As String
Dim MyStream As System.IO.Stream
myFileCollection = Request.Files
myFile = myFileCollection ( 0 )
FileLen = myFile.ContentLength
Dim Input ( FileLen ) As Byte
' Initialize the stream.
MyStream = myFile.InputStream
' Read the file into the byte array.
MyStream.Read ( input, 0, FileLen )
' Copy the byte array into a string.
For Loop1 = 0 To FileLen-1
MyString = MyString & Input ( Loop1 ).ToString ( )
Next Loop1
[ C# ]
HttpFileCollection myFileCollection;
HttpPostedFile myFile;
int FileLen;
System.IO.Stream MyStream;
myFileCollection = Request.Files;
myFile = myFileCollection [ 0 ];
FileLen = myFile.ContentLength;
byte [ ] input = new byte [ FileLen ];
// Initialize the stream.
MyStream = myFile.InputStream;
// Read the file into the byte array.
MyStream.Read ( input, 0, FileLen );
// Copy the byte array into a string.
for ( int Loop1 = 0; Loop1 < FileLen; Loop1++ )
MyString = MyString + input [ Loop1 ].ToString ( );
HttpPostedFile Members HttpFileCollection Class