Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

HttpPostedFile Class

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

System.Object
  System.Web.HttpPostedFile

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public sealed class HttpPostedFile

The HttpPostedFile type exposes the following members.

  NameDescription
Public propertyContentLengthGets the size of an uploaded file, in bytes.
Public propertyContentTypeGets the MIME content type of a file sent by a client.
Public propertyFileNameGets the fully qualified name of the file on the client.
Public propertyInputStreamGets a Stream object that points to an uploaded file to prepare for reading the contents of the file.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSaveAsSaves the contents of an uploaded file.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

TopicLocation
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.