Search Results for

# Legacy UploadPersistedFile

UploadPersistedFile is the compatibility control for pages that keep one uploaded file attached to a record.

Typical examples are:

- profile photos
- a single signed document
- one attachment per database row

## Typical markup

    <%@ Register Assembly="AjaxUploader" Namespace="CuteWebUI" TagPrefix="CuteWebUI" %>

    <CuteWebUI:UploadPersistedFile ID="ProfilePhotoUpload" runat="server"
        InsertText="Select file"
        OnFileChanged="ProfilePhotoUpload_FileChanged">
        <ValidateOption AllowedFileExtensions="jpg,png" MaxSizeKB="4096" />
    </CuteWebUI:UploadPersistedFile>

## Typical code-behind

    protected void ProfilePhotoUpload_FileChanged(object sender, CuteWebUI.PersistedFileEventArgs e)
    {
        var targetFolder = Server.MapPath("~/App_Data/ProfilePhotos");
        System.IO.Directory.CreateDirectory(targetFolder);
        var safeFileName = System.IO.Path.GetFileName(e.File.FileName ?? string.Empty);
        if (string.IsNullOrEmpty(safeFileName)) return;
        var targetPath = System.IO.Path.Combine(targetFolder, safeFileName);
        e.File.CopyTo(targetPath);
    }

## Most-used members

Member | Purpose
--- | ---
`File` | Gets the current persisted file wrapper
`FileChanged` | Fires when the selected persisted file changes
`ChangeFile(...)` | Replaces the current file by uploading a new one
`ClearFile()` | Clears the current persisted file selection

## Behavior to expect

- The control tracks one current file.
- The `File` property is available after the upload has been synchronized back through postback.
- The persisted file wrapper exposes helper methods such as `CopyTo`, `MoveTo`, `Delete`, and `OpenStream`.

## Related types

- PersistedFile
- PersistedFileEventArgs
- UploaderProvider