0

Hi all . . i need to develop an uploader for my website . . i done it . but the progress bar not working . . plz do help me ..

thanks in advance . .
--Karthik

this is my code .

aspx page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>File Upload page</title>
    <style type="text/css">
        #container
        {
        	background-color:silver;
        }
        

        
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container">
    
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br/>
        <asp:FileUpload ID="FileUpload2" runat="server" />
    
    
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="upload" 
            Width="83px" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="cancel" 
            Width="78px" />
            <br/>
            <br/>
        <asp:Label ID="lblMessages" runat="server"></asp:Label>
    <br />
    <asp:Panel ID="PanelProgress" runat="server" Width="23px" BackColor="Lime">
   
        <asp:Panel ID="PanelBarside" runat="server" Width="300px" 
    ForeColor="Silver">
            <asp:Image ID="Image1" runat="server" Height="16px" ImageUrl="loadbar.gif" 
                Width="62px" />
        </asp:Panel>
    </asp:Panel>
        
        <br/>
        
        <asp:Label id="lblpercent"
        runat="server" ForeColor="blue" ></asp:Label>
        <br />
    <br />
         </p>
         </div>
        </form>
</body>
</html>

aspx.cs page :

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.Web.SessionState;
using System.Text;
using System.Threading;


public partial class _Default : System.Web.UI.Page
{
    private int state = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["State"] != null)
        {

            state = Convert.ToInt32(Session["State"].ToString());
        }
        else
        {

            Session["State"] = 0;
        }
        if (state > 0 && state <= 10)
        {

            this.lblMessages.Text = "Processing...";
            this.PanelProgress.Width = state * 30;
            this.lblpercent.Text = state * 10 + "%";
            Page.RegisterStartupScript("", " ");
        }

        if (state == 100)
        {

            this.PanelProgress.Visible = false;
            this.PanelBarside.Visible = false;
            this.lblMessages.Text = "Task Completed!";
            Page.RegisterStartupScript("", " ");
        }
    }


        
    private void LongTask()
    {


        for (int i = 0; i < 11; i++)
        {
            System.Threading.Thread.Sleep(1000);
            Session["State"] = i + 1;
        }
        Session["State"] = 100;


    }

    public static void OpenProgressBar(System.Web.UI.Page Page)
    {

        StringBuilder sbScript = new StringBuilder();

        sbScript.Append(" \n");
        Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString());
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Thread thread = new Thread(new ThreadStart(LongTask));
        thread.Start();

        Session["State"] = 1;
        OpenProgressBar(this.Page);
        

                
        if (FileUpload1.HasFile)
           FileUpload1.SaveAs("c://fileupload//" + FileUpload1.FileName);   
       
           
        
       if (FileUpload2.HasFile)
        FileUpload2.SaveAs("c://fileupload//" + FileUpload2.FileName);

     }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx");
    }
    
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by aspproject
0

use ajax based progress bar when uploading image using file upload ..your solution

Edited by aspproject: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.