Centre for Software Practice

the blog
Welcome to Centre for Software Practice Sign in | Join | Help
in Search

Ajax File Upload

Last post 07-15-2007, 2:16 PM by David.Glance. 0 replies.
Sort Posts: Previous Next
  •  07-15-2007, 2:16 PM 36

    Ajax File Upload

    Description: AJAXFileUpload allows the client to upload a file to the server.

    The uploaded files are displayed with a description and the option to Delete the uploaded file.

    The class can be customised, giving the option as to whether the user can delete the uploaded file and/or view more than one uploaded file.

    To include AJAXFileUpload in "default.aspx", with multiple file upload displayed and the delete option available, enter:

    <uc2:AjaxFileUpload ID="AjaxFileUpload1" runat="server" FilePath="cache" AllowDelete="true"
                        MultiUpload="true" Visible="true" ControlToValidate="AjaxFileUpload1" EnableClientScript="false" />

    where the destination of uploaded files is the directory "cache". 

    Uploading a File: When the upload button is pressed, an asynchronous event trigger occurs, which starts a javascript postback. Upon postback, the source filepath is obtained and an attempt is made to upload it to the server distination path, specified in "default.aspx". During this process, the filesize, filename and filetype are recorded and, if multiple uploads is enabled, entered into a databinder repeater.

    Validation: The class has a validation function, which requires a filepath to be selected. It checks that there is a valid filepath, in the hasfile() function. If hasfile() returns true, then validatestring() will return a string and the validation will not produce any errors. However, if hasfile() returns false, then validatestring() will not return a string and the page will not be validated.

     The validation function:
        [ValidationPropertyAttribute("validatestring")]

    where validatestring() is a 'dummy function':

        public string validatestring
            {
                get { return (this.HasFile) ? "blah" : ""; }
            }


    Databind Repeater: The databind repeater records and does the formatting for the displaying of multiple uploaded files. It stores file information and indexes them.

    rUploadFiles_ItemCommand: This function executes the requested command. At the current version, there is only one command, which is delete. The actual deletion of the uploaded file occurs in this function. Once the file is deleted, the databind repeater is re-executed to update the file records. This function can be expanded, in the future, to have other item commands available to the user.

    Filed under: ,
View as RSS news feed in XML
Powered by Community Server (Personal Edition), by Telligent Systems