Implementing upload progress indicator question

Discussion in 'ASP .Net' started by Marko Vuksanovic, Jun 24, 2006.

  1. I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what might be wrong?

    FileUpload2.aspx

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

    <!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 id="Head1" runat="server">
    <title> drag </title>

    </head>
    <body>

    <form id="f1" enctype="multipart/form-data" runat="server">
    <h4>Select a file to upload:</h4>

    <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    <atlas:UpdatePanel ID="upResults" runat="server" Mode="conditional">
    <Triggers>
    <atlas:ControlEventTrigger ControlID="Upload" EventName="Click" />
    </Triggers>
    <ContentTemplate>
    </ContentTemplate>
    </atlas:UpdatePanel>


    <asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>


    <br /><br />


    <asp:Button id="Upload" Text="Upload file" OnClick="UploadButton_Click" runat="server">
    </asp:Button>
    <atlas:UpdateProgress ID="uprProgress" runat="server">

    <ProgressTemplate>
    <img src="images/animated_loading.gif" /> Uploading....
    </ProgressTemplate>
    </atlas:UpdateProgress>


    </form>
    </body>
    </html>

    FileUpload2.aspx.cs

    using .....;


    public partial class FileUpload2 : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void UploadButton_Click(object sender, EventArgs e)
    {
    // Specify the path on the server to save the uploaded file to.
    String savePath = @"C:\Temp\uploads\";
    // Before attempting to perform operations on the file, verify that the FileUpload control contains a file.
    if (FileUpload.HasFile)
    {
    String fileName = FileUpload.FileName;
    savePath += fileName;
    // Call the SaveAs method to save the uploaded file to the specified path.
    FileUpload.SaveAs(savePath);
    // Notify the user of the name of the file was saved under.
    // UploadStatusLabel.Text = "Your file was saved as " + fileName;
    }
    else
    {
    // Notify the user that a file was not uploaded.
    // UploadStatusLabel.Text = "You did not specify a file to upload.";
    }
    }
    }

    Any suggestions what might be wrong?

    Thanks,
    Marko Vuksanovic.
    Marko Vuksanovic, Jun 24, 2006
    #1
    1. Advertising

  2. Marko Vuksanovic

    Guest

    There are several ways to do progress bar.
    try this one below
    http://www.atlasasp.com/Cat/Articles/Atlas_Progress_Bar/default.aspx


    Marko Vuksanovic wrote:
    > I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what might be wrong?
    >
    > FileUpload2.aspx
    >
    > <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload2.aspx.cs" Inherits="FileUpload2" %>
    >
    > <!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 id="Head1" runat="server">
    > <title> drag </title>
    >
    > </head>
    > <body>
    >
    > <form id="f1" enctype="multipart/form-data" runat="server">
    > <h4>Select a file to upload:</h4>
    >
    > <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    > <atlas:UpdatePanel ID="upResults" runat="server" Mode="conditional">
    > <Triggers>
    > <atlas:ControlEventTrigger ControlID="Upload" EventName="Click" />
    > </Triggers>
    > <ContentTemplate>
    > </ContentTemplate>
    > </atlas:UpdatePanel>
    >
    >
    > <asp:FileUpload id="FileUpload" runat="server"> </asp:FileUpload>
    >
    >
    > <br /><br />
    >
    >
    > <asp:Button id="Upload" Text="Upload file" OnClick="UploadButton_Click" runat="server">
    > </asp:Button>
    > <atlas:UpdateProgress ID="uprProgress" runat="server">
    >
    > <ProgressTemplate>
    > <img src="images/animated_loading.gif" /> Uploading....
    > </ProgressTemplate>
    > </atlas:UpdateProgress>
    >
    >
    > </form>
    > </body>
    > </html>
    >
    > FileUpload2.aspx.cs
    >
    > using .....;
    >
    >
    > public partial class FileUpload2 : System.Web.UI.Page
    > {
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > }
    >
    > protected void UploadButton_Click(object sender, EventArgs e)
    > {
    > // Specify the path on the server to save the uploaded file to.
    > String savePath = @"C:\Temp\uploads\";
    > // Before attempting to perform operations on the file, verify that the FileUpload control contains a file.
    > if (FileUpload.HasFile)
    > {
    > String fileName = FileUpload.FileName;
    > savePath += fileName;
    > // Call the SaveAs method to save the uploaded file to the specified path.
    > FileUpload.SaveAs(savePath);
    > // Notify the user of the name of the file was saved under.
    > // UploadStatusLabel.Text = "Your file was saved as " + fileName;
    > }
    > else
    > {
    > // Notify the user that a file was not uploaded.
    > // UploadStatusLabel.Text = "You did not specify a file to upload.";
    > }
    > }
    > }
    >
    > Any suggestions what might be wrong?
    >
    > Thanks,
    > Marko Vuksanovic.
    >
    > ------=_NextPart_000_0019_01C697E8.978EE8D0
    > Content-Type: text/html; charset=iso-8859-2
    > Content-Transfer-Encoding: quoted-printable
    > X-Google-AttachSize: 13449
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML><HEAD>
    > <META http-equiv=Content-Type content="text/html; charset=windows-1250">
    > <STYLE></STYLE>
    >
    > <META content="MSHTML 6.00.5384.4" name=GENERATOR></HEAD>
    > <BODY id=MailContainerBody
    > style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-TOP: 15px"
    > bgColor=#ffffff leftMargin=0 topMargin=0 CanvasTabStop="true" acc_role="text"
    > name="Compose message area">
    > <DIV><FONT face=Arial size=2>
    > <DIV><FONT face=Arial size=2>I used the following code for implementing a file
    > upload progress indicator, using UpdateProgress Panel, though I have a problem
    > that FileUpload.Has File always returns false. Any suggestions what might be
    > wrong?</FONT></DIV>
    > <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
    > <DIV><FONT size=2>
    > <P><FONT face=Arial>FileUpload2.aspx</FONT></P>
    > <P>&lt;%</FONT><FONT color=#0000ff size=2>@</FONT><FONT size=2> </FONT><FONT
    > color=#800000 size=2>Page</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>Language</FONT><FONT color=#0000ff size=2>="C#"</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>AutoEventWireup</FONT><FONT color=#0000ff
    > size=2>="true"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>CodeFile</FONT><FONT color=#0000ff
    > size=2>="FileUpload2.aspx.cs"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>Inherits</FONT><FONT color=#0000ff size=2>="FileUpload2"</FONT><FONT
    > size=2> %&gt;</P></FONT><FONT color=#0000ff size=2>
    > <P>&lt;!</FONT><FONT color=#800000 size=2>DOCTYPE</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>html</FONT><FONT size=2> </FONT><FONT
    > color=#ff0000 size=2>PUBLIC</FONT><FONT size=2> </FONT><FONT color=#0000ff
    > size=2>"-//W3C//DTD XHTML 1.0 Transitional//EN"</FONT><FONT size=2> </FONT><FONT
    > color=#0000ff
    > size=2>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;</P></FONT><FONT
    > size=2>
    > <P></P></FONT><FONT color=#0000ff size=2>
    > <P>&lt;</FONT><FONT color=#800000 size=2>html</FONT><FONT size=2> </FONT><FONT
    > color=#ff0000 size=2>xmlns</FONT><FONT color=#0000ff
    > size=2>="http://www.w3.org/1999/xhtml"</FONT><FONT size=2> </FONT><FONT
    > color=#0000ff size=2>&gt;<BR>&lt;</FONT><FONT color=#800000
    > size=2>head</FONT><FONT size=2> </FONT><FONT color=#ff0000 size=2>id</FONT><FONT
    > color=#0000ff size=2>="Head1"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>runat</FONT><FONT color=#0000ff size=2>="server"&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;</FONT><FONT color=#800000 size=2>title</FONT><FONT
    > color=#0000ff size=2>&gt;</FONT><FONT size=2> drag </FONT><FONT color=#0000ff
    > size=2>&lt;/</FONT><FONT color=#800000 size=2>title</FONT><FONT color=#0000ff
    > size=2>&gt;</P>
    > <P>&lt;/</FONT><FONT color=#800000 size=2>head</FONT><FONT color=#0000ff
    > size=2>&gt;<BR>&lt;</FONT><FONT color=#800000 size=2>body</FONT><FONT
    > color=#0000ff size=2>&gt;</FONT><FONT size=2> </P>
    > <P></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>form</FONT><FONT size=2> </FONT><FONT color=#ff0000 size=2>id</FONT><FONT
    > color=#0000ff size=2>="f1"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>enctype</FONT><FONT color=#0000ff
    > size=2>="multipart/form-data"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>runat</FONT><FONT color=#0000ff size=2>="server"&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;</FONT><FONT color=#800000 size=2>h4</FONT><FONT
    > color=#0000ff size=2>&gt;</FONT><FONT size=2>Select a file to
    > upload:</FONT><FONT color=#0000ff size=2>&lt;/</FONT><FONT color=#800000
    > size=2>h4</FONT><FONT color=#0000ff size=2>&gt;</FONT></P>
    > <P><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>atlas</FONT><FONT color=#0000ff size=2>:</FONT><FONT color=#800000
    > size=2>ScriptManager</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>ID</FONT><FONT color=#0000ff size=2>="ScriptManager1"</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>runat</FONT><FONT color=#0000ff
    > size=2>="server"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>EnablePartialRendering</FONT><FONT color=#0000ff
    > size=2>="true"</FONT><FONT size=2> </FONT><FONT color=#0000ff
    > size=2>/&gt;<BR></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>atlas</FONT><FONT color=#0000ff size=2>:</FONT><FONT color=#800000
    > size=2>UpdatePanel</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>ID</FONT><FONT color=#0000ff size=2>="upResults"</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>runat</FONT><FONT color=#0000ff
    > size=2>="server"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>Mode</FONT><FONT color=#0000ff size=2>="conditional"&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;</FONT><FONT color=#800000 size=2>Triggers</FONT><FONT
    > color=#0000ff size=2>&gt;<BR></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT
    > color=#800000 size=2>atlas</FONT><FONT color=#0000ff size=2>:</FONT><FONT
    > color=#800000 size=2>ControlEventTrigger</FONT><FONT size=2> </FONT><FONT
    > color=#ff0000 size=2>ControlID</FONT><FONT color=#0000ff
    > size=2>="Upload"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>EventName</FONT><FONT color=#0000ff size=2>="Click"</FONT><FONT size=2>
    > </FONT><FONT color=#0000ff size=2>/&gt;<BR></FONT><FONT color=#0000ff
    > size=2>&lt;/</FONT><FONT color=#800000 size=2>Triggers</FONT><FONT color=#0000ff
    > size=2>&gt;<BR></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>ContentTemplate</FONT><FONT color=#0000ff size=2>&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;/</FONT><FONT color=#800000
    > size=2>ContentTemplate</FONT><FONT color=#0000ff size=2>&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;/</FONT><FONT color=#800000 size=2>atlas</FONT><FONT
    > color=#0000ff size=2>:</FONT><FONT color=#800000 size=2>UpdatePanel</FONT><FONT
    > color=#0000ff size=2>&gt;</P></FONT><FONT size=2>
    > <P></P>
    > <P></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>asp</FONT><FONT color=#0000ff size=2>:</FONT><FONT color=#800000
    > size=2>FileUpload</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>id</FONT><FONT color=#0000ff size=2>="FileUpload"</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>runat</FONT><FONT color=#0000ff
    > size=2>="server"&gt;</FONT><FONT size=2> </FONT><FONT color=#0000ff
    > size=2>&lt;/</FONT><FONT color=#800000 size=2>asp</FONT><FONT color=#0000ff
    > size=2>:</FONT><FONT color=#800000 size=2>FileUpload</FONT><FONT color=#0000ff
    > size=2>&gt;</P></FONT><FONT size=2>
    > <P></P>
    > <P></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>br</FONT><FONT size=2> </FONT><FONT color=#0000ff
    > size=2>/&gt;&lt;</FONT><FONT color=#800000 size=2>br</FONT><FONT size=2>
    > </FONT><FONT color=#0000ff size=2>/&gt;</P></FONT><FONT size=2>
    > <P></P>
    > <P></FONT><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>asp</FONT><FONT color=#0000ff size=2>:</FONT><FONT color=#800000
    > size=2>Button</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>id</FONT><FONT color=#0000ff size=2>="Upload"</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>Text</FONT><FONT color=#0000ff size=2>="Upload
    > file" </FONT><FONT color=#ff0000 size=2>OnClick</FONT><FONT color=#0000ff
    > size=2>="UploadButton_Click" </FONT><FONT color=#ff0000 size=2>runat</FONT><FONT
    > color=#0000ff size=2>="server"&gt;<BR></FONT><FONT color=#0000ff
    > size=2>&lt;/</FONT><FONT color=#800000 size=2>asp</FONT><FONT color=#0000ff
    > size=2>:</FONT><FONT color=#800000 size=2>Button</FONT><FONT color=#0000ff
    > size=2>&gt;</FONT><FONT size=2> <BR></FONT><FONT color=#0000ff
    > size=2>&lt;</FONT><FONT color=#800000 size=2>atlas</FONT><FONT color=#0000ff
    > size=2>:</FONT><FONT color=#800000 size=2>UpdateProgress</FONT><FONT size=2>
    > </FONT><FONT color=#ff0000 size=2>ID</FONT><FONT color=#0000ff
    > size=2>="uprProgress"</FONT><FONT size=2> </FONT><FONT color=#ff0000
    > size=2>runat</FONT><FONT color=#0000ff size=2>="server"&gt;</FONT></P>
    > <P><FONT color=#0000ff size=2>&lt;</FONT><FONT color=#800000
    > size=2>ProgressTemplate</FONT><FONT color=#0000ff size=2>&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;</FONT><FONT color=#800000 size=2>img</FONT><FONT
    > size=2> </FONT><FONT color=#ff0000 size=2>src</FONT><FONT color=#0000ff
    > size=2>="images/animated_loading.gif"</FONT><FONT size=2> </FONT><FONT
    > color=#0000ff size=2>/&gt;</FONT><FONT size=2> Uploading....<BR></FONT><FONT
    > color=#0000ff size=2>&lt;/</FONT><FONT color=#800000
    > size=2>ProgressTemplate</FONT><FONT color=#0000ff size=2>&gt;<BR></FONT><FONT
    > color=#0000ff size=2>&lt;/</FONT><FONT color=#800000 size=2>atlas</FONT><FONT
    > color=#0000ff size=2>:</FONT><FONT color=#800000
    > size=2>UpdateProgress</FONT><FONT color=#0000ff size=2>&gt;</P></FONT><FONT
    > size=2>
    > <P></P>
    > <P></FONT><FONT color=#0000ff size=2>&lt;/</FONT><FONT color=#800000
    > size=2>form</FONT><FONT color=#0000ff size=2>&gt;<BR></FONT><FONT color=#0000ff
    > size=2>&lt;/</FONT><FONT color=#800000 size=2>body</FONT><FONT color=#0000ff
    > size=2>&gt;<BR>&lt;/</FONT><FONT color=#800000 size=2>html</FONT><FONT
    > color=#0000ff size=2>&gt;</FONT></P>
    > <P><FONT color=#000000 size=2>FileUpload2.aspx.cs</FONT></P><FONT color=#0000ff
    > size=2><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
    > <P>using</FONT><FONT size=2><FONT color=#000000> .....;</FONT></FONT>
    > <P><FONT size=2><FONT color=#000000></FONT></P></FONT><FONT color=#0000ff
    > size=2>public</FONT><FONT color=#000000 size=2> </FONT><FONT color=#0000ff
    > size=2>partial</FONT><FONT color=#000000 size=2> </FONT><FONT color=#0000ff
    > size=2>class</FONT><FONT color=#000000 size=2> </FONT><FONT color=#008080
    > size=2>FileUpload2</FONT><FONT color=#000000 size=2> :
    > System.Web.UI.</FONT><FONT color=#008080 size=2>Page<BR></FONT><FONT
    > size=2>{<BR></FONT><FONT color=#0000ff size=2>protected</FONT><FONT size=2>
    > </FONT><FONT color=#0000ff size=2>void</FONT><FONT size=2>
    > Page_Load(</FONT><FONT color=#0000ff size=2>object</FONT><FONT size=2> sender,
    > </FONT><FONT color=#008080 size=2>EventArgs</FONT><FONT size=2> e)<BR>{<BR>}
    > <P></P>
    > <P></FONT><FONT color=#0000ff size=2>protected</FONT><FONT size=2> </FONT><FONT
    > color=#0000ff size=2>void</FONT><FONT size=2> UploadButton_Click(</FONT><FONT
    > color=#0000ff size=2>object</FONT><FONT size=2> sender, </FONT><FONT
    > color=#008080 size=2>EventArgs</FONT><FONT size=2> e)<BR>{<BR></FONT><FONT
    > color=#008000 size=2>// Specify the path on the server to&nbsp;</FONT><FONT
    > color=#008000 size=2> save the uploaded file to.<BR></FONT><FONT color=#008080
    > size=2>String</FONT><FONT size=2> savePath = </FONT><FONT color=#800000
    > size=2>@"C:\Temp\uploads\"</FONT><FONT size=2>;<BR></FONT><FONT color=#008000
    > size=2>// Before attempting to perform operations&nbsp;</FONT><FONT
    > color=#008000 size=2> on the file, verify that the FileUpload&nbsp;</FONT><FONT
    > color=#008000 size=2> control contains a file.<BR></FONT><FONT color=#0000ff
    > size=2>if</FONT><FONT size=2> (FileUpload.HasFile)<BR>{<BR></FONT><FONT
    > color=#008080 size=2>String</FONT><FONT size=2> fileName =
    > FileUpload.FileName;<BR></FONT><FONT size=2>savePath +=
    > fileName;<BR></FONT><FONT color=#008000 size=2>// Call the SaveAs method to save
    > the&nbsp;</FONT><FONT color=#008000 size=2> uploaded file to the specified
    > path.<BR></FONT><FONT size=2>FileUpload.SaveAs(savePath);<BR></FONT><FONT
    > color=#008000 size=2>// Notify the user of the name of the file</FONT><FONT
    > color=#008000 size=2> was saved under.<BR>// UploadStatusLabel.Text = "Your file
    > was saved as " + fileName;<BR></FONT><FONT size=2>}<BR></FONT><FONT
    > color=#0000ff size=2>else<BR></FONT><FONT size=2>{<BR></FONT><FONT color=#008000
    > size=2>// Notify the user that a file was not uploaded.<BR>//
    > UploadStatusLabel.Text = "You did not specify a file to
    > upload.";<BR></FONT><FONT size=2>}<BR>}<BR>}</P>
    > <P><FONT face=Arial color=#000000>Any suggestions what might be
    > wrong?</FONT></P>
    > <P><FONT face=Arial color=#000000>Thanks,<BR>Marko
    > Vuksanovic.</FONT></P></FONT></FONT></FONT></DIV></FONT></DIV></BODY></HTML>
    >
    > ------=_NextPart_000_0019_01C697E8.978EE8D0--
    , Jun 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dale Ragan via .NET 247

    HttpHandler Progress Indicator

    Dale Ragan via .NET 247, Aug 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    580
    Rick Strahl [MVP]
    Aug 6, 2004
  2. Koen Janssens

    terminal progress indicator

    Koen Janssens, Nov 25, 2003, in forum: C++
    Replies:
    10
    Views:
    748
    Peter Koch Larsen
    Nov 29, 2003
  3. Marko Vuksanovic

    File Upload Progress Indicator

    Marko Vuksanovic, Jun 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    552
  4. Marko Vuksanovic

    File Upload Progress Indicator ?

    Marko Vuksanovic, Jun 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    10,940
  5. Frantisek Fuka

    Progress indicator during FTP upload

    Frantisek Fuka, Jan 4, 2004, in forum: Python
    Replies:
    3
    Views:
    596
    Samuel Walters
    Jan 5, 2004
Loading...

Share This Page