Re: Problem In Implementing Uploader in Code Behind Page in asp.net

  •  01-04-2009, 11:46 PM

    Re: Problem In Implementing Uploader in Code Behind Page in asp.net

    Hi ssjal,
     
    Here is the example code:
     
    simple-upload-Validation.aspx
     
     
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="simple-upload-Validation.aspx.cs"
        Inherits="simple_upload_Validation" %>
    <!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 runat="server">
        <title>Simple Upload with Progress</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div class="content">
                    <asp:ScriptManager ID="Scriptmanager1" runat="server">
                    </asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <h2>
                                Simple Upload with Progress (Custom Validation)
                            </h2>
                            <p>
                                A sample demonstrating how to create user-defined validation functions for an upload
                                control. In this example, we defined two validation rules:</p>
                            <ul>
                                <li>Maximum file size: 100K</li><li>Allowed file types: jpeg, jpg, gif,png </li>
                            </ul>
                            <p>
                                Click the following button to upload.
                            </p>
                            <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Upload">
                                <ValidateOption AllowedFileExtensions="jpeg,jpg,gif,png" MaxSizeKB="100" />
                            </CuteWebUI:Uploader>
                            <br />
                            <br />
                            <div>
                                Server Trace:
                                <br />
                                <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                            </div>
                            <br />
                            <br />
                            <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </form>
    </body>
    </html>
    code behind
     
    simple-upload-Validation.aspx.cs
     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class simple_upload_Validation : System.Web.UI.Page
    {
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            SampleUtil.SetPageCache();
            Uploader1.FileUploaded += new CuteWebUI.UploaderEventHandler(Uploader_FileUploaded);
            ButtonPostBack.Click += new EventHandler(ButtonPostBack_Click);

        }

        void ButtonPostBack_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked a PostBack Button.");
        }

        void Uploader_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
        {
            CuteWebUI.Uploader uploader = (CuteWebUI.Uploader)sender;
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
        }

    }


     
     
    Regards,
     
    Ken
View Complete Thread