Editare

Partajați prin


HttpPostedFile Class

Definition

Provides access to individual files that have been uploaded by a client.

public ref class HttpPostedFile sealed
public sealed class HttpPostedFile
type HttpPostedFile = class
Public NotInheritable Class HttpPostedFile
Inheritance
HttpPostedFile

Remarks

The HttpFileCollection class provides access to all the files that are uploaded from a client as a file collection. The HttpPostedFile class provides properties and methods to get information about an individual file and to read and save the file.

The HtmlInputFile control can be used to select and upload files from a client.

Files are uploaded in MIME multipart/form-data format. By default, all requests, including form fields and uploaded files, larger than 256 KB are buffered to disk, rather than held in server memory.

You can specify the maximum allowable request size by accessing the MaxRequestLength property or by setting the maxRequestLength attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file. The default is 4 MB.

The amount of data that is buffered in server memory for a request, which includes file uploads, can be specified by accessing the RequestLengthDiskThreshold property or by setting the requestLengthDiskThreshold attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file.

By adjusting the MaxRequestLength and RequestLengthDiskThreshold properties, you can fine tune the performance of your server. Additionally, you should consider setting the MaxRequestLength to prevent denial of service attacks caused by users posting large files to the server.

Server resources that are allocated to buffer the uploaded file will be destroyed when the request ends. To save a durable copy of the file, use the SaveAs method.

Properties

ContentLength

Gets the size of an uploaded file, in bytes.

ContentType

Gets the MIME content type of a file sent by a client.

FileName

Gets the fully qualified name of the file on the client.

InputStream

Gets a Stream object that points to an uploaded file to prepare for reading the contents of the file.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SaveAs(String)

Saves the contents of an uploaded file.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also