HttpFileCollection Classe
Definição
Fornece acesso aos arquivos carregados por um cliente e os organiza.Provides access to and organizes files uploaded by a client.
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
- Herança
Exemplos
O exemplo a seguir demonstra como acessar a HttpFileCollection coleção retornada da Files Propriedade do HttpRequest objeto.The following example demonstrates how to access the HttpFileCollection collection returned from the Files property of the HttpRequest object. A HttpFileCollection coleção é preenchida por dois FileUpload controles na página da Web.The HttpFileCollection collection is populated by two FileUpload controls on the Web page. Os itens na coleção de arquivos são exibidos em um BulletedList controle.Items in the file collection are displayed in a BulletedList control.
<%@ 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>
Comentários
Os clientes codificam arquivos e os transmitem no corpo de conteúdo usando o formato MIME de várias partes com um Content-Type cabeçalho HTTP de multipart/form-data .Clients encode files and transmit them in the content body using multipart MIME format with an HTTP Content-Type header of multipart/form-data. ASP.NET extrai os arquivos codificados do corpo de conteúdo em membros individuais de um HttpFileCollection .ASP.NET extracts the encoded file(s) from the content body into individual members of an HttpFileCollection. Os métodos e as propriedades da HttpPostedFile classe fornecem acesso ao conteúdo e às propriedades de cada arquivo.Methods and properties of the HttpPostedFile class provide access to the contents and properties of each file.
Propriedades
| AllKeys |
Obtém uma matriz de cadeia de caracteres que contém as chaves (nomes) de todos os membros da coleção de arquivos.Gets a string array containing the keys (names) of all members in the file collection. |
| Count |
Obtém o número de pares chave-valor contidos na instância NameObjectCollectionBase.Gets the number of key/value pairs contained in the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| IsReadOnly |
Obtém ou define um valor que indica se a instância de NameObjectCollectionBase é somente leitura.Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only. (Herdado de NameObjectCollectionBase) |
| Item[Int32] |
Obtém o objeto com o índice numérico especificado do HttpFileCollection.Gets the object with the specified numerical index from the HttpFileCollection. |
| Item[String] |
Retorna o objeto com o nome especificado da coleção de arquivos.Gets the object with the specified name from the file collection. |
| Keys |
Obtém uma instância de NameObjectCollectionBase.KeysCollection que contém todas as chaves da instância de NameObjectCollectionBase.Gets a NameObjectCollectionBase.KeysCollection instance that contains all the keys in the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
Métodos
| BaseAdd(String, Object) |
Adiciona uma entrada com a chave e o valor especificados à instância NameObjectCollectionBase.Adds an entry with the specified key and value into the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseClear() |
Remove todas as entradas da instância NameObjectCollectionBase.Removes all entries from the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGet(Int32) |
Obtém o valor da entrada no índice especificado da instância NameObjectCollectionBase.Gets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGet(String) |
Obtém o valor da primeira entrada com a chave especificada da instância de NameObjectCollectionBase.Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGetAllKeys() |
Retorna uma matriz String que contém todas as chaves na instância NameObjectCollectionBase.Returns a String array that contains all the keys in the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGetAllValues() |
Retorna uma matriz Object que contém todos os valores na instância NameObjectCollectionBase.Returns an Object array that contains all the values in the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGetAllValues(Type) |
Retorna uma matriz do tipo especificado que contém todos os valores na instância NameObjectCollectionBase.Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseGetKey(Int32) |
Obtém a chave da entrada no índice especificado da instância NameObjectCollectionBase.Gets the key of the entry at the specified index of the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseHasKeys() |
Obtém um valor que indica se a instância NameObjectCollectionBase contém entradas cujas chaves não são |
| BaseRemove(String) |
Remove as entradas com a chave especificada da instância de NameObjectCollectionBase.Removes the entries with the specified key from the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseRemoveAt(Int32) |
Remove a entrada no índice especificado da instância NameObjectCollectionBase.Removes the entry at the specified index of the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseSet(Int32, Object) |
Define o valor da entrada no índice especificado da instância NameObjectCollectionBase.Sets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| BaseSet(String, Object) |
Define o valor da primeira entrada com a chave especificada na instância NameObjectCollectionBase, se encontrada; caso contrário, adiciona uma entrada com a chave especificada e o valor para a instância NameObjectCollectionBase.Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| CopyTo(Array, Int32) |
Copia os membros da coleção de arquivos para uma Array começando no índice especificado da matriz.Copies members of the file collection to an Array beginning at the specified index of the array. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| Get(Int32) |
Retorna o objeto HttpPostedFile com o índice numérico especificado da coleção de arquivos.Returns the HttpPostedFile object with the specified numerical index from the file collection. |
| Get(String) |
Retorna o objeto HttpPostedFile com o nome especificado da coleção de arquivos.Returns the HttpPostedFile object with the specified name from the file collection. |
| GetEnumerator() |
Retorna um enumerador que itera por meio de NameObjectCollectionBase.Returns an enumerator that iterates through the NameObjectCollectionBase. (Herdado de NameObjectCollectionBase) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetKey(Int32) |
Retorna o nome do membro HttpFileCollection com o índice numérico especificado.Returns the name of the HttpFileCollection member with the specified numerical index. |
| GetMultiple(String) |
Retorna todos os arquivos que correspondem ao nome especificado.Returns all files that match the specified name. |
| GetObjectData(SerializationInfo, StreamingContext) |
Implementa a interface ISerializable e retorna os dados necessários para serializar a instância NameObjectCollectionBase.Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance. (Herdado de NameObjectCollectionBase) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| OnDeserialization(Object) |
Implementa a interface ISerializable e gera o evento de desserialização quando a desserialização for concluída.Implements the ISerializable interface and raises the deserialization event when the deserialization is complete. (Herdado de NameObjectCollectionBase) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
Implantações explícitas de interface
| ICollection.CopyTo(Array, Int32) |
Copia todo o NameObjectCollectionBase em um Array unidimensional compatível, começando no índice especificado da matriz de destino.Copies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array. (Herdado de NameObjectCollectionBase) |
| ICollection.IsSynchronized |
Obtém um valor que indica se o acesso ao objeto NameObjectCollectionBase é sincronizado (thread-safe).Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe). (Herdado de NameObjectCollectionBase) |
| ICollection.SyncRoot |
Obtém um objeto que pode ser usado para sincronizar o acesso ao objeto NameObjectCollectionBase.Gets an object that can be used to synchronize access to the NameObjectCollectionBase object. (Herdado de NameObjectCollectionBase) |
Métodos de Extensão
| Cast<TResult>(IEnumerable) |
Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type. |
| OfType<TResult>(IEnumerable) |
Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type. |
| AsParallel(IEnumerable) |
Habilita a paralelização de uma consulta.Enables parallelization of a query. |
| AsQueryable(IEnumerable) |
Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable. |