Bagikan melalui


HttpFileCollection Kelas

Definisi

Menyediakan akses ke dan mengatur file yang diunggah oleh klien.

public ref class HttpFileCollection sealed : System::Collections::Specialized::NameObjectCollectionBase
public sealed class HttpFileCollection : System.Collections.Specialized.NameObjectCollectionBase
type HttpFileCollection = class
    inherit NameObjectCollectionBase
Public NotInheritable Class HttpFileCollection
Inherits NameObjectCollectionBase
Warisan
HttpFileCollection

Contoh

Contoh berikut menunjukkan cara mengakses koleksi yang HttpFileCollection dikembalikan dari Files properti HttpRequest objek. Koleksi HttpFileCollection diisi oleh dua FileUpload kontrol pada halaman Web. Item dalam kumpulan file ditampilkan dalam BulletedList kontrol.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        // Clear the BulletedList.
        BulletedList1.Items.Clear();
        
        // Check to see if at least one file was specified.
        if (FileUpload1.HasFile | FileUpload2.HasFile)
        {
            Label1.Text = "The file collection consists of:";
            
            // Get the HttpFileCollection.
            HttpFileCollection hfc = Request.Files;
            foreach (String h in hfc.AllKeys)
            {
                // Add an item to the BulletedList if a file
                // was specified for the corresponding control.
                if (hfc[h].ContentLength > 0)
                    BulletedList1.Items.Add(Server.HtmlEncode(hfc[h].FileName));
            }
            
        }
        else
        {
            Label1.Text = "You did not specify any files to upload or " +
                "the file(s) could not be found.";
        }

    }        
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpFileCollection Example</title>
</head>
<body>
    <form id="form1" 
          runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" 
                        runat="server" />
        <br />
        <asp:FileUpload ID="FileUpload2" 
                        runat="server" />
        <br />
        <asp:Button ID="Button1" 
                    runat="server" 
                    OnClick="Button1_Click" 
                    Text="Upload" />
        <br />
        <asp:Label ID="Label1" 
                   runat="server"/>
        <br />
        <asp:BulletedList ID="BulletedList1" 
                          runat="server">
        </asp:BulletedList>
        </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        ' Clear the BulletedList.
        BulletedList1.Items.Clear()
        
        ' Check to see if at least one file was specified.
        If (FileUpload1.HasFile Or FileUpload2.HasFile) Then
            
            Label1.Text = "The file collection consists of:"
            
            ' Get the HttpFileCollection.
            Dim hfc As HttpFileCollection = Request.Files
            For Each h As String In hfc.AllKeys
                
                ' Add an item to the BulletedList if a file
                ' was specified for the corresponding control.
                If (hfc(h).ContentLength > 0) Then
                    BulletedList1.Items.Add(Server.HtmlEncode(hfc(h).FileName))
                End If
            Next
        Else
            
            Label1.Text = "You did not specify any files to upload or " & _
                "the file(s) could not be found."
            
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>HttpFileCollection Example</title>
</head>
<body>
    <form id="form1" 
          runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" 
                        runat="server" />
        <br />
        <asp:FileUpload ID="FileUpload2" 
                        runat="server" />
        <br />
        <asp:Button ID="Button1" 
                    runat="server" 
                    OnClick="Button1_Click" 
                    Text="Upload" />
        <br />
        <asp:Label ID="Label1" 
                   runat="server"/>
        <br />
        <asp:BulletedList ID="BulletedList1" 
                          runat="server">
        </asp:BulletedList>
        </div>
    </form>
</body>
</html>

Keterangan

Klien mengodekan file dan mengirimkannya dalam isi konten menggunakan format MIME multipart dengan header HTTP Content-Type .multipart/form-data ASP.NET mengekstrak file yang dikodekan dari isi konten ke anggota individu dari HttpFileCollection. Metode dan properti HttpPostedFile kelas menyediakan akses ke konten dan properti setiap file.

Properti

Nama Deskripsi
AllKeys

Mendapatkan array string yang berisi kunci (nama) semua anggota dalam koleksi file.

Count

Mendapatkan jumlah pasangan kunci/nilai yang terkandung dalam NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
IsReadOnly

Mendapatkan atau menetapkan nilai yang menunjukkan apakah NameObjectCollectionBase instans bersifat baca-saja.

(Diperoleh dari NameObjectCollectionBase)
Item[Int32]

Mendapatkan objek dengan indeks numerik yang ditentukan dari HttpFileCollection.

Item[String]

Mendapatkan objek dengan nama yang ditentukan dari koleksi file.

Keys

Mendapatkan instans NameObjectCollectionBase.KeysCollection yang berisi semua kunci dalam NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)

Metode

Nama Deskripsi
BaseAdd(String, Object)

Menambahkan entri dengan kunci dan nilai yang ditentukan ke NameObjectCollectionBase dalam instans.

(Diperoleh dari NameObjectCollectionBase)
BaseClear()

Menghapus semua entri dari NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseGet(Int32)

Mendapatkan nilai entri pada indeks NameObjectCollectionBase instans yang ditentukan.

(Diperoleh dari NameObjectCollectionBase)
BaseGet(String)

Mendapatkan nilai entri pertama dengan kunci yang ditentukan dari NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseGetAllKeys()

Mengembalikan String array yang berisi semua kunci dalam NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseGetAllValues()

Mengembalikan Object array yang berisi semua nilai dalam NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseGetAllValues(Type)

Mengembalikan array dari jenis yang ditentukan yang berisi semua nilai dalam NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseGetKey(Int32)

Mendapatkan kunci entri pada indeks instans yang NameObjectCollectionBase ditentukan.

(Diperoleh dari NameObjectCollectionBase)
BaseHasKeys()

Mendapatkan nilai yang menunjukkan apakah NameObjectCollectionBase instans berisi entri yang kuncinya bukan null.

(Diperoleh dari NameObjectCollectionBase)
BaseRemove(String)

Menghapus entri dengan kunci yang ditentukan dari NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
BaseRemoveAt(Int32)

Menghapus entri pada indeks instans yang NameObjectCollectionBase ditentukan.

(Diperoleh dari NameObjectCollectionBase)
BaseSet(Int32, Object)

Mengatur nilai entri pada indeks NameObjectCollectionBase instans yang ditentukan.

(Diperoleh dari NameObjectCollectionBase)
BaseSet(String, Object)

Mengatur nilai entri pertama dengan kunci yang ditentukan dalam NameObjectCollectionBase instans, jika ditemukan; jika tidak, menambahkan entri dengan kunci dan nilai yang ditentukan ke NameObjectCollectionBase dalam instans.

(Diperoleh dari NameObjectCollectionBase)
CopyTo(Array, Int32)

Menyalin anggota kumpulan file ke Array awal pada indeks array yang ditentukan.

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
Get(Int32)

Mengembalikan HttpPostedFile objek dengan indeks numerik yang ditentukan dari kumpulan file.

Get(String)

Mengembalikan HttpPostedFile objek dengan nama yang ditentukan dari koleksi file.

GetEnumerator()

Mengembalikan enumerator yang berulang melalui NameObjectCollectionBase.

(Diperoleh dari NameObjectCollectionBase)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetKey(Int32)

Mengembalikan nama HttpFileCollection anggota dengan indeks numerik yang ditentukan.

GetMultiple(String)

Mengembalikan semua file yang cocok dengan nama yang ditentukan.

GetObjectData(SerializationInfo, StreamingContext)
Kedaluwarsa.

ISerializable Mengimplementasikan antarmuka dan mengembalikan data yang diperlukan untuk membuat serialisasi NameObjectCollectionBase instans.

(Diperoleh dari NameObjectCollectionBase)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
OnDeserialization(Object)

ISerializable Menerapkan antarmuka dan meningkatkan peristiwa deserialisasi ketika deserialisasi selesai.

(Diperoleh dari NameObjectCollectionBase)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

Nama Deskripsi
ICollection.CopyTo(Array, Int32)

Menyalin seluruh NameObjectCollectionBase ke satu dimensi Arrayyang kompatibel , dimulai pada indeks array target yang ditentukan.

(Diperoleh dari NameObjectCollectionBase)
ICollection.IsSynchronized

Mendapatkan nilai yang menunjukkan apakah akses ke objek disinkronkan NameObjectCollectionBase (utas aman).

(Diperoleh dari NameObjectCollectionBase)
ICollection.SyncRoot

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke NameObjectCollectionBase objek.

(Diperoleh dari NameObjectCollectionBase)

Metode Ekstensi

Nama Deskripsi
AsParallel(IEnumerable)

Mengaktifkan paralelisasi kueri.

AsQueryable(IEnumerable)

Mengonversi IEnumerable menjadi IQueryable.

Cast<TResult>(IEnumerable)

Melemparkan elemen IEnumerable ke jenis yang ditentukan.

OfType<TResult>(IEnumerable)

Memfilter elemen IEnumerable berdasarkan jenis tertentu.

Berlaku untuk

Lihat juga