HttpRequest.Files Property

Definition

Gets the collection of files uploaded by the client, in multipart MIME format.

C#
public System.Web.HttpFileCollection Files { get; }

Property Value

An HttpFileCollection object representing a collection of files uploaded by the client. The items of the HttpFileCollection object are of type HttpPostedFile.

Examples

The following code example displays the names of all files in the Files collection.

C#
int loop1;
HttpFileCollection Files;

Files = Request.Files; // Load File collection into HttpFileCollection variable.
arr1 = Files.AllKeys;  // This will get names of all files into a string array.
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
    Response.Write("File: " + Server.HtmlEncode(arr1[loop1]) + "<br />");
    Response.Write("  size = " + Files[loop1].ContentLength + "<br />");
    Response.Write("  content type = " + Files[loop1].ContentType + "<br />");
}

Remarks

The file collection is populated only when the HTTP request Content-Type value is "multipart/form-data".

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1