InputStream Property
.NET Framework Class Library
HttpPostedFile..::.InputStream Property

Gets a Stream object that points to an uploaded file to prepare for reading the contents of the file.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public ReadOnly Property InputStream As Stream
Visual Basic (Usage)
Dim instance As HttpPostedFile
Dim value As Stream

value = instance.InputStream
C#
public Stream InputStream { get; }
Visual C++
public:
property Stream^ InputStream {
    Stream^ get ();
}
JScript
public function get InputStream () : Stream

Property Value

Type: System.IO..::.Stream
A Stream pointing to a file.

The following code example shows how to read the contents of the first file in the client's file collection into a byte array, and then copy the byte array to a string.

Visual Basic
Imports System
Imports System.Web
Imports System.Web.UI

Public Class Page1: Inherits Page

 Protected Loop1 As Integer
 Protected MyString As String

  Protected Sub Page_Load(sender As Object, e As EventArgs)

    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

 End Sub

End Class
C#
using System;
using System.Web;
using System.Web.UI;

public class Page1: Page
{
 protected string MyString;
 private void Page_Load(Object sender, EventArgs e)
 {
   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();

 }
}
JScript
import System
import System.Web
import System.Web.UI

class Page1 extends Page{

 var myString : String

  function Page_Load(sender : Object, e : EventArgs){
    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()
    }

   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
Page view tracker