asp.net.ph

HttpPostedFile.InputStream Property

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;

Property Value

A Stream pointing to a file.

Example

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 ( );
See Also

HttpPostedFile Members   HttpFileCollection Class Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph