This documentation is archived and is not being maintained.
HttpPostedFile.InputStream Property
.NET Framework 1.1
Gets a Stream object which points to an uploaded file to prepare for reading the contents of the file.
[Visual Basic] 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.
[Visual Basic] 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(); [C++] HttpFileCollection* MyFileCollection; HttpPostedFile* MyFile; int FileLen; System::IO::Stream* MyStream; MyFileCollection = Request->Files; MyFile = MyFileCollection->Item[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 = String::Concat( MyString, __box(input[Loop1])); [JScript] var myFileCollection : HttpFileCollection var myFile : HttpPostedFile var fileLen : int var myString : String = "" var myStream : System.IO.Stream myFileCollection = Request.Files myFile = myFileCollection[0] fileLen = myFile.ContentLength var input : Byte[] = 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(var i=0; i < fileLen; i++){ myString = myString + input[i].ToString() }
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HttpPostedFile Class | HttpPostedFile Members | System.Web Namespace
Show: