Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads
 
Add your own
alternative version

ASP.NET - Upload File With Loading Image using JavaScript and C#

, 18 Mar 2009 CPOL
ASP.NET - Upload File with Loading Image appears after Start Uploading
DemoProject.zip
UploadFileWithLoadingImage
App_Data
bin
UploadFileWithLoadingImage.dll
UploadFileWithLoadingImage.pdb
IFrame
Images
loading.gif
JavaScript
Properties
UploadFileWithLoadingImage.csproj.user
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;



namespace FileUploadWithProgressBar
{
    /// <summary>
    /// This page will be used to save the uploded file,and then hide the progress bar image.
    /// </summary>
    public partial class FileUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                //Get the root folder from web config.
                string rootFolder = ConfigurationManager.AppSettings["RootFolder"].ToString();

                //Get the full file path which we will use it to save the file.
                string fileName = rootFolder + @"ProfileName.doc";

                //Save the file on the specified path
                FileUpload1.SaveAs(fileName);

                //Suspend the current thread,this line should be removed in real code.
                Thread.Sleep(5000);

                //Hide the upload panel
                pnlUpload.Visible = false;

                //View message to notify the user that the his file has been uploaded.
                pnlAfterUpload.Visible = true;

                //Call javascript function to hide progress bar image
                Page.ClientScript.RegisterStartupScript(this.GetType()
                                                        , @"CloseProgressbar",
                                                        @"HideProgress();", true);
            }
            catch (Exception x)
            {
                throw x;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Malik Hassan
Technical Lead E-Pulse for electronic solutions - Amman,Jordan
Jordan Jordan
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 19 Mar 2009
Article Copyright 2009 by Malik Hassan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid