I am using a ProgressBar. Inside the server side method handling the request, I poll an object in a separate thread until it is done reading a file from an FTP server, updating the percentage complete as appropriate. This all works fine.
At the end, when the file is completely read, I want to do this:
MultiView1.SetActiveView(View2);Before I rewrote things to use the ProgressBar, it would cause the other view to load and its page_load to be called, which would commence subsequent processing of the file.
Now that code is never reached. Here is the C# method on the server:
Code: C#
protected void UploadProgressBar1_RunTask(object sender, EO.Web.ProgressTaskEventArgs e)
{
string errorMsg = "";
ErrorMsgLabel.Text = "";
try
{
//System.Threading.Thread.Sleep(10000); // For testing the spinner.
string url = this.PDFUrl.Text;
string fetchedFile = null;
if (!url.ToLower().Contains(".pdf"))
{
errorMsg = "The file to be uploaded must have the extension 'pdf'.";
throw new Exception(errorMsg);
}
errorMsg = "System error. Unable to retrieve path to temporary file directory.";
string tempFileLocation = Path.GetTempPath();
errorMsg = "System error. Unable to compose path to final location for PDF file.";
string finalFileLocation = Path.Combine(ConfigurationManager.AppSettings["UploadPath"], ClientIdHdn.Value);
errorMsg = "System error. Unable to test existence of directory which will hold PDF file.";
if (!Directory.Exists(finalFileLocation))
{
errorMsg = "System error. Unable to create directory which will hold uploaded PDF file.";
Directory.CreateDirectory(finalFileLocation);
}
// Initiate the process of fetching the named file using FTP.
FtpHelper ftpHelper = new FtpHelper(url, finalFileLocation);
_ftpHelper = ftpHelper;
if (ftpHelper.HasError)
{
errorMsg = ftpHelper.Status;
throw new Exception("FtpHelper reports error: " + errorMsg);
}
ftpHelper.GetFileAsync();
while (!ftpHelper.IsDone)
{
e.UpdateProgress(ftpHelper.PercentComplete, null);
System.Threading.Thread.Sleep(100);
}
FtpHelper.DownloadFileInfo info = ftpHelper.FileInfo;
if (ftpHelper.HasError)
{
errorMsg = ftpHelper.Status;
throw new Exception("FtpHelper reports error: " + errorMsg);
}
if (info.FileSize > 0)
{
string basename = Path.GetFileName(info.FilePath);
PdfFileNameHdn.Value = basename;
}
e.UpdateProgress(100, null);
ErrorMsgLabel.Text = "";
MultiView1.SetActiveView(View2);
}
catch (Exception ex)
{
e.UpdateProgress(100, null);
ErrorMsgLabel.Text = errorMsg;
_ftpHelper = null;
// Cause error message to become visible on web page.
//throw new Exception(errorMsg);
}
}
- Paul