HttpPostedFile.InputStream-Eigenschaft
Ruft ein Stream-Objekt ab, das auf eine geuploadete Datei zeigt, um das Lesen des Dateiinhalts vorzubereiten.
Namespace: System.Web
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public ReadOnly Property InputStream As Stream
'Usage
Dim instance As HttpPostedFile
Dim value As Stream
value = instance.InputStream
public Stream InputStream { get; }
public:
property Stream^ InputStream {
Stream^ get ();
}
/** @property */
public Stream get_InputStream ()
public function get InputStream () : Stream
Eigenschaftenwert
Ein Stream, der auf eine Datei zeigt.
Beispiel
Im folgenden Beispiel wird veranschaulicht, wie der Inhalt der ersten Datei in der Dateiauflistung des Clients in ein Bytearray eingelesen und dieses anschließend in eine Zeichenfolge kopiert wird.
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
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();
}
}
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()
}
}
}
Plattformen
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
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HttpPostedFile-Klasse
HttpPostedFile-Member
System.Web-Namespace