アップロードされたファイルを示す Stream オブジェクトを取得し、そのファイルの内容を読み取る準備をします。
Public ReadOnly Property InputStream As Stream
[C#]
public Stream InputStream {get;}
[C++]
public: __property Stream* get_InputStream();
[JScript]
public function get InputStream() : Stream;
プロパティ値
ファイルを示す Stream 。
使用例
クライアントのファイル コレクションの最初のファイルの内容をバイト配列に読み込んで、そのバイト配列を文字列にコピーする例を次に示します。
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()
}
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ