Progress bar

P

Paulo

Hi, while the user is uploading a file, is possible to show a progress bar?
Using VS 2005 Asp.net 2.0 C#

Thanks!
 
M

Mike

It is but why? The file upload takes like a second, so your progress bar
will never been seen.
Now if you were uploading the file and processing it all at the same time,
then maybe the progress bar can be seen, but just for an upload, makes no
sense due to the time it takes for it to upload.
 
S

Steve

The server doesn't know what size the file is until it's done uploading,
so I think your best option is to either use an animated gif to show
"something" while the upload is going on, or use AJAX. The postback
itself will contain the file, so you'll need to use client-side code to
do the displaying.

Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
M

Mike

true, but regardless of what is used, the upload takes a second or so, so it
may never even be seen by the user.
I have an upload page and I tried adding one to it, but due to the time it
actually took to upload the file the user never saw the progress/animation
on the screen.
 
S

Steve

The OP didn't say anything about how large the file is. It could be a
10MB file, which would take longer than a second or two?



Steve C.
MCSD,MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
P

Paulo

The file size may vary, example if the size is 10MB @ 10/KBs will take ~
5mins... I dont know the user bandwidth... so I would like to show to him
some progress..

Thanks!
 
J

Juan T. Llibre

re:
!> The server doesn't know what size the file is until it's done uploading

Indeed.

re:
!> so I think your best option is to either use an animated gif to show
!> "something" while the upload is going on, or use AJAX.

Another option would be to use an animated GIF to keep the user
entertained while the upload finishes and create a FileSystemWatcher
object to redirect the user to "uploadFinished.aspx" when the file has finished uploading.

To do that, you'll have to import the FileSystemWatcher namespace :

System.IO.FileSystemWatcher

Something like this ?

public void CreateWatcher()
{
//Create a new FileSystemWatcher
FileSystemWatcher watcher = newFileSystemWatcher();

//Set the filter to only catch ZIP files.
watcher.Filter = "*.zip";

// Perhaps a variable could be created to hold the exact name
// of the file in the filter, obtained from the File.Upload textbox.

//Subscribe to the Created event.
watcher.Created += new FileSystemEventHandler(watcher_FileCreated);

//Set the monitored path to your upload directory
watcher.Path = @"C:\Temp\";

//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}

void watcher_FileCreated(object sender, FileSystemEventArgs e)
{
//When the .zip file has been created in C:\Temp\ ...
Response.Redirect("~/uploadFinished.aspx", false);
return;
}

I haven't done this...but it seems quite possible.
If you try it, please let us know if it worked.
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top