This documentation is archived and is not being maintained.

FileUpload Constructor

Initializes a new instance of the FileUpload class.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
FileUpload()

Use the FileUpload constructor to initialize a new instance of the FileUpload class. The FileUpload control does not automatically save a file to the server after the user selects the file to upload. You must explicitly provide a control or mechanism to allow the user to submit the specified file. For example, you can provide a button that the user clicks to upload the file.

The following example demonstrates how to initialize a new instance of the FileUpload class. Note that this example demonstrates the constructor syntax but does not add functionality to the control after it is created.

This example is part of a larger example provided for the FileUpload class.


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>FileUpload Constructor Example</title>
<script runat="server">

        Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

            ' Create a FileUpload control.
            Dim FileUpload1 As New FileUpload

            ' Add the FileUpload control to the Controls collection
            ' of the PlaceHolder control.
            PlaceHolder1.Controls.Add(FileUpload1)

        End Sub

    </script>

</head>
<body>

    <h3>FileUpload Constructor Example</h3>

    <form id="Form1" runat="server">

        <asp:PlaceHolder id="PlaceHolder1"                 
            runat="server">
        </asp:PlaceHolder>

        <hr />

         <asp:Button id="Button1" 
             Text="Create and show a FileUpload control" 
             OnClick="Button1_Click" 
             runat="server"/>              

    </form>

</body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.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.
Show: