HttpPostedFile.InputStream プロパティ
アセンブリ: System.Web (system.web.dll 内)


クライアントのファイル コレクションの最初のファイルの内容をバイト配列に読み込んで、そのバイト配列を文字列にコピーする方法を次のコード例に示します。
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() } } }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpPostedFile.InputStream プロパティを検索する場合は、下記のリンクをクリックしてください。

- HttpPostedFile.InputStream プロパティのページへのリンク