File Upload Progress Logic Help

P

pbd22

Hi.

I have a question about how to best let my user know the status of
files being uploaded (please - no links to third party software or
file upload projects).

The way I am attacking this problem is below. My core question is at
the bottom when I talk about how to construct the logic inside the
GetStatus() Web Service method.

I have Page.aspx.cs and, in the codebehind, I have a loop:

List<ServerVariable> files = new List<ServerVariable>();

for (i = 0; i <= Request.Files.Count - 1; i++)
{

m_objFile = Request.Files;
m_strFileName = m_objFile.FileName;
m_strFileName = Path.GetFileName(m_strFileName);

files.Add(new ServerVariable(i.ToString(),
this.m_strFileName, "0"));

}

//CODE TO COPY A FILE FOR UPLOAD TO THE
//WEB SERVER

//WHEN THE UPLOAD IS DONE, SET THE ITEM TO
//COMPLETED

int index = files.FindIndex(p => p.Completed == "0");
files[index] = new ServerVariable(i.ToString(),
this.m_strFileName, "1");

The "ServerVariable" type gets and sets ID, File, and Completed.

Now, I need to show the user the file upload "progress" (in effect,
the time between when the loop adds the ServerVariable item to the
list to when the Completed status changes from 0 to 1.

Now, I have a web service method "GetStatus()" that I would like to
use to return the files list (created above) as a JSON string (via
JQuery). Files with a completed status of 0 are still in progress,
files with a 1 are done.

MY QUESTION IS - what does the code inside GetStatus() look like? How
do I query List<ServerVariable > **as* it is being populated and
return the results in a real-time way?

If I have explained myself well, I'd appreciate a code illustration of
the logic in GetStatus().

Thanks for reading.
 
P

Peter Duniho

[...]
Now, I have a web service method "GetStatus()" that I would like to
use to return the files list (created above) as a JSON string (via
JQuery). Files with a completed status of 0 are still in progress,
files with a 1 are done.

MY QUESTION IS - what does the code inside GetStatus() look like? How
do I query List<ServerVariable > **as* it is being populated and
return the results in a real-time way? [...]

The basic idea seems somewhat problematic to me. If I understand the
question correctly, you have a service running on a server, and a UI being
displayed on a client computer (in a browser). The problem is that the
client-side display is a static result from an HTTP query (GET). Updating
that from the server side, after it's already been loaded by the
client-side browser, is a problem.

Ignoring that aspect, it seems that you would need a way to update the UI
both when items are added to your list of files, as well as when the
status for an already-added item changes. In a single-process solution,
this would generally be handled simply by using some kind of signal
(typically, an event) to indicate those changes, and then some code to
update the display accordingly (typically, using a cross-thread
invocation, since the processing usually wouldn't happen on the GUI
thread). It's also possible a Queue<T> would be used instead of a
List<T>, or at least there would be some index marker used so that it's
easy to tell when updating the UI what's actually new in the List<T>.

But how to raise those events remotely, so that a client-side UI can
present them to the user, I don't know. I'm sure it can be accomplished
in some awkward way, such as having the client-side UI poll the server
periodically (using AJAX/JSON/etc. rather than reloading a whole page, I
presume). Maybe this is in fact what you mean by the "GetStatus() web
service method". But I'm not aware of any event-driven technique you can
use (and as far as the GetStatus() method goes, surely it's no more
difficult than just making sure you've synchronized access to the shared
List<T> data structure and inspecting it for changes).

Of course, you're asking an ASP.NET question, but have posted it in a C#
newsgroup. If you actually want a really useful, practical, and informed
answer, you probably should post your question to the ASP.NET newsgroup.
:)

Pete
 
P

pbd22

[...]
Now, I have a web service method "GetStatus()" that I would like to
use to return the files list (created above) as a JSON string (via
JQuery). Files with a completed status of 0 are still in progress,
files with a 1 are done.
MY QUESTION IS - what does the code inside GetStatus() look like? How
do I query List<ServerVariable > **as* it is being populated and
return the results in a real-time way? [...]

The basic idea seems somewhat problematic to me.  If I understand the  
question correctly, you have a service running on a server, and a UI being  
displayed on a client computer (in a browser).  The problem is that the 
client-side display is a static result from an HTTP query (GET).  Updating  
that from the server side, after it's already been loaded by the  
client-side browser, is a problem.

Ignoring that aspect, it seems that you would need a way to update the UI 
both when items are added to your list of files, as well as when the  
status for an already-added item changes.  In a single-process solution,  
this would generally be handled simply by using some kind of signal  
(typically, an event) to indicate those changes, and then some code to  
update the display accordingly (typically, using a cross-thread  
invocation, since the processing usually wouldn't happen on the GUI  
thread).  It's also possible a Queue<T> would be used instead of a  
List<T>, or at least there would be some index marker used so that it's  
easy to tell when updating the UI what's actually new in the List<T>.

But how to raise those events remotely, so that a client-side UI can  
present them to the user, I don't know.  I'm sure it can be accomplished  
in some awkward way, such as having the client-side UI poll the server  
periodically (using AJAX/JSON/etc. rather than reloading a whole page, I  
presume).  Maybe this is in fact what you mean by the "GetStatus() web  
service method".  But I'm not aware of any event-driven technique you can  
use (and as far as the GetStatus() method goes, surely it's no more  
difficult than just making sure you've synchronized access to the shared  
List<T> data structure and inspecting it for changes).

Of course, you're asking an ASP.NET question, but have posted it in a C#  
newsgroup.  If you actually want a really useful, practical, and informed  
answer, you probably should post your question to the ASP.NET newsgroup.  
:)

Pete

Thanks for your response Peter. You are correct, I am polling the web
service from the client UI to get status updates.

Per your suggestion, I will repost in the appropriate forum.

Thanks again.
 

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