Skip to content

<FileUpload>

The FileUpload tag allows your users to upload a file to your web server. It supports three display modes: upload a file directly, pick from existing files in a directory, or pick from existing files with the option to upload new ones.

Example

html
<AddForm>
  ...
  <table>
    <tr>
      <td>
        <Label For="txtFirstName" Text="First Name" />
        <Textbox Id="txtFirstName" DataField="FirstName" DataType="String" />
      </td>
    </tr>
    <tr>
      <td>
        <Label For="txtLastName" Text="Last Name" />
        <Textbox Id="txtLastName" DataField="LastName" DataType="String" />
       </td>
    </tr>
    <tr>
      <td>
        <Label For="uplMugShot" Text="Mug Shot" />
        <FileUpload Id="uplMugShot" Path="~/images/" Extensions="gif,jpg"
          DataField="UserImage" DataType="String" />
       </td>
    </tr>
    <tr>
      <td colspan="2">
        <AddButton Text="Add"/>&nbsp;<CancelButton Text="Cancel"/>
      </td>
    </tr>
  </table>
</AddForm>

Properties

PropertyValuesDefaultDescription
ID *stringUnique identifier for the control within the form
DataFieldstringParameter name for data binding to your form's data commands
DataTypeStringStringDatabase type — always String for this control
DisplayModeUploadAndSelect FilePicker FilePickerNoUploadUploadAndSelectHow the control presents file selection to the user
ExtensionsstringComma-separated list of allowed file extensions, without the period (e.g. gif,jpg,png)
FileNameLabelCssClassstringNormalCSS class for the uploaded file name label
FilePickerCssClassstringNormalTextBoxCSS class for the file picker dropdown
MessageLabelCssClassstringNormalCSS class for error/status messages
NewFileButtonCssClassstringCommandButtonCSS class for the "new file" link button
NewFileButtonTextstringUpload FileText for the "new file" link button
NullableTrue FalseFalseReturns DBNull when no file has been uploaded
Path *stringServer directory where uploaded files are saved
UploadButtonCssClassstringCommandButtonCSS class for the upload button
UploadButtonTextstringUploadText for the upload button
UseUniqueFileNameTrue FalseFalseGenerates a unique GUID-based filename for uploads
VisibleTrue FalseTrueShows or hides the control

* Required property

NOTE

Because of JavaScript's security mechanisms, the FileUpload control will NOT function if Partial Page Rendering has been enabled for the XMod Pro module. This is true of the ASP.NET FileUpload control and is not specific to XMod Pro's FileUpload control.

Validating the FileUpload Control: The nature of the FileUpload control does not allow it to be validated on the client. If you use a validator with this control, set the EnableClientScript attribute to false.

Property Details

  • ID: Name, consisting of letters and numbers, beginning with a letter, that uniquely identifies the control within the form.

  • DataField: Name of the parameter in the <SubmitCommand> which will be filled with this control's data when the form is submitted and/or the parameter in the <SelectCommand> which will supply this control's data when the form is loaded. This attribute is required if the control will participate in operations with your form's data commands.

  • DisplayMode: Determines how the control presents file selection to the user:

    • UploadAndSelect (default): The user uploads a file and that file becomes the selected value. This is the classic behavior from earlier versions of the control.
    • FilePicker: Files in the specified directory are displayed in a drop-down list for the user to choose from. No upload capability is provided.
    • FilePickerNoUpload: Same as FilePicker — files are displayed in a drop-down list — but the user also has the ability to upload a new file.
  • Extensions: A comma-delimited list of file extensions that define the file types allowed to be uploaded. File extensions should not include the period. For instance: gif,jpg,tiff is a valid value.

    WARNING

    If Extensions is not set, all file types will be accepted with no restrictions. Always specify allowed extensions to prevent unwanted file uploads.

  • Nullable: If True, the control will return a DBNull value when no file has been uploaded. If a DBNull value is passed to the control, regardless of the Nullable setting, no value will be set for the uploaded file.

  • Path: The path on the web server where the file should be saved. This path must be accessible to the web application and permissions must be set to allow file operations. The path should be written relative to the web application root and may use the tilde (~) character to represent the root. Examples: /Portals/0/images/ or ~/Portals/0/images/

  • UseUniqueFileName: When set to True, the control will generate a unique GUID-based name for the uploaded file. If False, the original file name will be used.