Implementing upload progress indicator question


M

Marko Vuksanovic

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.
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top