I am using the RadUpdate/ProgressArea control to allow a user to upload a file and then view the status of the import process. The first progress bar is handled automatically during the update process by the progress area. The second part of the process, the import, I am using the secondary progress bar to give them feedback (processing line x of y).
************* ERROR MESSAGE *****************
RadUpload Ajax callback error. Source url returned invalid content:
var rawProgressData = {InProgress:true,ProgressCounters:true,PrimaryPercent:'100'System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
at Telerik.Web.UI.Upload.ProgressData.Serialize(TextWriter writer)
at Telerik.Web.UI.RadProgressContext.Serialize(TextWriter writer)
at Telerik.Web.UI.RadUploadProgressHandler.ProcessRequest(HttpContext context)
Telerik.RadUploadProgressHandler.ashx?RadUrid=9ab592e1-0d6a-43f2-8f5e-9eddc5e20105
Did you register the RadUploadProgressHandler in web.config?
Please, see the help for more details: RadUpload for ASP.NET Ajax - Configuration - RadUploadProgressHandler.
***************** End of Error ******************
Any ideas what is causing this?
Thanks!
**************** Sample Code ********************
UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[0]);
string fileName = MapPath("uploads") + "\\" + file.GetName();
file.SaveAs(fileName, true);
if (!Object.Equals(file, null))
{
importFile(fileName);
}
private void importFile(string fileName)
{
ArrayList lines = new ArrayList();
RadProgressContext progress = RadProgressContext.Current;
DateTime startTime = DateTime.Now;
progress.SecondaryTotal = 100;
progress.SecondaryValue = 0;
progress.SecondaryPercent = 0;
progress.CurrentOperationText = "Reading File..";
StreamReader reader = new StreamReader(fileName);
try
{
int totalLines = 0;
while (!reader.EndOfStream)
{
totalLines++;
lines.Add(reader.ReadLine());
}
progress.SecondaryTotal = totalLines;
progress.CurrentOperationText = "Importing Data...";
for (int line = 0; line < totalLines; line++)
{
//progressContext.PrimaryPercent = (int)Math.Round(((decimal)i / count) * 100, 0);
progress.SecondaryValue = line;
progress.CurrentOperationText = "Importing Data...(" + line + " of " + totalLines + ")";
TimeSpan elapsed = DateTime.Now.Subtract(startTime);
progress.TimeElapsed = string.Format("{0:D2}:{1:D2}:{2:D2} s", elapsed.Hours, elapsed.Minutes, elapsed.Seconds);
double estimatedMillisecons = 24 * 60 * 60 * 1000;
if (line != 0)
{
estimatedMillisecons = totalLines * elapsed.TotalMilliseconds / line;
}
TimeSpan estimated = TimeSpan.FromSeconds(1);
if (estimatedMillisecons > 1)
{
estimated = TimeSpan.FromMilliseconds(estimatedMillisecons);
}
progress.TimeEstimated = string.Format("{0:D2}:{1:D2}:{2:D2} s", estimated.Hours, estimated.Minutes, estimated.Seconds);
double speed = 0.0d;
if (elapsed.TotalSeconds > 0)
{
speed = line / elapsed.TotalSeconds;
}
progress.Speed = string.Format("{0:0.00} steps/s", speed);
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
}
}
catch (Exception ex)
{
App.ProcessException(this, ex);
throw ex;
}
finally
{
if (reader != null)
reader.Close();
}
}
************* ERROR MESSAGE *****************
RadUpload Ajax callback error. Source url returned invalid content:
var rawProgressData = {InProgress:true,ProgressCounters:true,PrimaryPercent:'100'System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
at Telerik.Web.UI.Upload.ProgressData.Serialize(TextWriter writer)
at Telerik.Web.UI.RadProgressContext.Serialize(TextWriter writer)
at Telerik.Web.UI.RadUploadProgressHandler.ProcessRequest(HttpContext context)
Telerik.RadUploadProgressHandler.ashx?RadUrid=9ab592e1-0d6a-43f2-8f5e-9eddc5e20105
Did you register the RadUploadProgressHandler in web.config?
Please, see the help for more details: RadUpload for ASP.NET Ajax - Configuration - RadUploadProgressHandler.
***************** End of Error ******************
Any ideas what is causing this?
Thanks!
**************** Sample Code ********************
UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[0]);
string fileName = MapPath("uploads") + "\\" + file.GetName();
file.SaveAs(fileName, true);
if (!Object.Equals(file, null))
{
importFile(fileName);
}
private void importFile(string fileName)
{
ArrayList lines = new ArrayList();
RadProgressContext progress = RadProgressContext.Current;
DateTime startTime = DateTime.Now;
progress.SecondaryTotal = 100;
progress.SecondaryValue = 0;
progress.SecondaryPercent = 0;
progress.CurrentOperationText = "Reading File..";
StreamReader reader = new StreamReader(fileName);
try
{
int totalLines = 0;
while (!reader.EndOfStream)
{
totalLines++;
lines.Add(reader.ReadLine());
}
progress.SecondaryTotal = totalLines;
progress.CurrentOperationText = "Importing Data...";
for (int line = 0; line < totalLines; line++)
{
//progressContext.PrimaryPercent = (int)Math.Round(((decimal)i / count) * 100, 0);
progress.SecondaryValue = line;
progress.CurrentOperationText = "Importing Data...(" + line + " of " + totalLines + ")";
TimeSpan elapsed = DateTime.Now.Subtract(startTime);
progress.TimeElapsed = string.Format("{0:D2}:{1:D2}:{2:D2} s", elapsed.Hours, elapsed.Minutes, elapsed.Seconds);
double estimatedMillisecons = 24 * 60 * 60 * 1000;
if (line != 0)
{
estimatedMillisecons = totalLines * elapsed.TotalMilliseconds / line;
}
TimeSpan estimated = TimeSpan.FromSeconds(1);
if (estimatedMillisecons > 1)
{
estimated = TimeSpan.FromMilliseconds(estimatedMillisecons);
}
progress.TimeEstimated = string.Format("{0:D2}:{1:D2}:{2:D2} s", estimated.Hours, estimated.Minutes, estimated.Seconds);
double speed = 0.0d;
if (elapsed.TotalSeconds > 0)
{
speed = line / elapsed.TotalSeconds;
}
progress.Speed = string.Format("{0:0.00} steps/s", speed);
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
}
}
catch (Exception ex)
{
App.ProcessException(this, ex);
throw ex;
}
finally
{
if (reader != null)
reader.Close();
}
}