Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HttpPostedFile Class

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

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class HttpPostedFile
Visual Basic (Usage)
Dim instance As HttpPostedFile
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpPostedFile
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HttpPostedFile sealed
JScript
public final class HttpPostedFile

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
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
How to: Upload Files with the FileUpload Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
System..::.Object
  System.Web..::.HttpPostedFile
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
This class can be accessed from the FileUpload control      CSharpUniversity.com   |   Edit   |   Show History
The HttpPostedFile object can be accessed from an ASP.NET FileUpload server control. Be careful when you allow users to upload files to your web server. If you want to see an example with source code and video, visit the following:
http://www.csharpuniversity.com/2009/03/05/uploading-files-and-validating-them-using-the-aspnet-fileupload-and-customvalidator-controls/

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker