Krystalware

SlickUpload Demos

» Overview Demonstrates the basics of SlickUpload. Selecting files, maximum file limit, file type validation, require files to be selected.
» FileNameGenerator How to control and generate server filenames for files as they are uploaded.
» Additional Fields How to add additional input fields for each selected file.
» Custom Progress Display custom progress information during a postprocessing step after files are uploaded.
» Localization How to localize the SlickUpload control.
» Modal Progress Show the progress display in a modal.
» Skinned Skin the file list and progress display.
» Upload to Amazon S3 How to upload to Amazon's Simple Storage Service with progress display.
» Upload to SQL Server Upload directly to a SQL Server, streaming with no memory usage.
Clustered» Use a StatusManager configuration to allow uploads with progress to a cluster/web farm/web garden.
» Custom UploadStreamProvider How to develop your own upload stream provider – this example shows how to zip files as they are uploaded.
» SimpleThe bare metal SlickUpload control, drag-dropped onto the page.

Overview Sample

General Settings
Max files: -1 Number of files, or -1 for unlimited
Require file selection: No
Confirm navigate message: Prompt when user navigates during upload
Validation
Valid extensions: Comma seperated list of valid extensions
Per file message: Message to display next to invalid files
Summary message: Summary validation message for invalid files

Select files to upload:

NOTE: the maximum allowed request size for this sample is 1024 MB. If you attempt to upload files larger than this, you will recieve a oversized upload error which SlickUpload will handle gracefully. This is controlled by the maxRequestLength attribute of the httpRuntime key in the web.config file.

Description

This is the overview sample, which demonstrates the basics of SlickUpload. The following concepts are covered in this sample:

Selecting files

The SlickUpload control is used to allow file selection. Files can be selected, removed, and uploaded. The SlickUpload control is fully templatable allowing customization of look and feel. This sample uses the bare metal SlickUpload skin.

Maximum file limit

The SlickUpload control has the capability to limit the number of files selected. By default, unlimited files are allowed, but by setting the MaxFiles property of the SlickUpload control, you can limit to any specific number. For example, to limit to three (3) files, you would set the MaxFiles property as follows:

<kw:SlickUpload ... MaxFiles="3" ... />

Require file selection

SlickUpload provides a rich client side object model that allows you to easily hook in and do validation checks. For this example, an ASP.NET CustomValidator is used, but you could easily replace this with whatever validation framework you use. The validation javascript looks like this:

function Validate_SlickUploadRequiredFiles(source, args)
{
    args.IsValid = (kw.get("<%=SlickUpload1.ClientID %>").get_Files().length > 0);
}

This validation function gets a reference to the SlickUpload control on the page, gets a list of the files currently selected, and checks its length to ensure at least one file has been selected. To hook this into the ASP.NET validation framework, you can use a CustomValidator configured as follows:

<asp:CustomValidator runat="server" ClientValidationFunction="Validate_SlickUploadRequiredFiles" Text="Please select at least one file to upload." />

Confirm navigate message

If the user navigates away from the page during an upload (this can occur by clicking a link, using the back or forward button, typing a url into the address bar, etc.), the upload will fail. This property allows you to specify a message that will prompt the user to make sure they want to navigate away before the upload is cancelled.

<kw:SlickUpload ... ConfirmNavigateDuringUploadMessage="Leaving will cancel the current upload!" ... />

Extension validation

The SlickUpload control has built in file extension validation. By default, all extensions are allowed. To turn on validation, set the ValidExtensions property of the SlickUpload control to a comma seperated list of extensions that are considered valid. For example, to allow images only, you might use a setting such as:

<kw:SlickUpload ... ValidExtensions=".png,.gif,.jpg" ... />

To set a validation message to be displayed next to each invalid file, set the InvalidExtensionMessage property of the SlickUpload control. For example:

<kw:SlickUpload ... InvalidExtensionMessage="Please select an image (*.png, *.gif, *.jpg)." ... />

You can also implement a seperate validator to display an additional message, or if you want a per page message instead of per file. To do this, use a validation javascript such as:

function Validate_SlickUploadValidExtensions(source, args)
{
    var files = kw.get("<%=SlickUpload1.ClientID %>").get_Files();

    args.IsValid = true;

    for (var i = 0; i < files.length; i++)
    {
        if (!files[i].isValidExtension)
        {
            args.IsValid = false;

            return;
        }
    }
}

This javascript is similar to the required file validation. It gets a reference to the SlickUpload control, gets a list of the files currently selected, and then iterates through the list to determine if any invalid files have been selected. To hook this into the ASP.NET validation framework, you can use a CustomValidator configured as follows:

<asp:CustomValidator runat="server" ClientValidationFunction="Validate_SlickUploadValidExtensions" Text="Please select an image (*.png, *.gif, *.jpg)." />