Click here to Skip to main content
12,304,566 members (66,032 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads

Stats

73.9K views
4.1K downloads
44 bookmarked
Posted

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
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
Software Developer Readify
Australia Australia
No Biography provided

You may also be interested in...

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