HttpPostedFile.InputStream Property
.NET Framework 2.0
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)
Assembly: System.Web (in system.web.dll)
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.
import System.*;
import System.Web.*;
import System.Web.UI.*;
public class Page1 extends Page
{
protected String myString;
private void Page_Load(Object sender, EventArgs e)
{
HttpFileCollection myFileCollection;
HttpPostedFile myFile;
int fileLen;
System.IO.Stream myStream;
myFileCollection = get_Request().get_Files();
myFile = myFileCollection.get_Item(0);
fileLen = myFile.get_ContentLength();
ubyte input[] = new ubyte[fileLen];
// Initialize the stream.
myStream = myFile.get_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.get_Item(loop1).ToString();
}
} //Page_Load
} //Page1
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 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: