using System;
using System.Data;
using System.Configuration;
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;

using System.Drawing;
using Telerik.WebControls;
using Telerik.WebControls.RadUploadUtils;

public partial class SimpleUpload : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        statusLabel.Text = "";
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (RadUpload1.InvalidFiles.Count == 0)
            {
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                {
                    file.SaveAs(@"c:\MyUploadDir\" + file.GetName(), true);
                }

                if (RadUpload1.UploadedFiles.Count > 0)
                    DisplayMessage("Upload successful", false);               
            }      

        }
        catch (Exception ex)
        {
            DisplayMessage("Upload failed" + ex.Message, true);
        }

    }
 
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (RadUpload1.InvalidFiles.Count == 0)
        {
            CustomValidator1.ErrorMessage = "";
            args.IsValid = true;
        }
        else
        {
            CustomValidator1.ErrorMessage = "File validation failed";
            args.IsValid = false;
        }
    }

    private void DisplayMessage(string text, bool isError)
    {
        this.statusLabel.Font.Bold = true;
        this.statusLabel.Visible = true;
        if (isError)
        {
            this.statusLabel.ForeColor = Color.Red;
        }
        else
        {
            this.statusLabel.ForeColor = Color.Green;
        }
        this.statusLabel.Text = text;
    }
}
