Rach Singh

Rach Singh

  • NA
  • 17
  • 0

Progress bar with Background worker till xml file gets uploaded.

Mar 2 2009 7:15 AM
Hi,
how i can run a progress bar on winform to tell the user to wait till the xml file is being uploaded in treeview on winform?
i am getting an exception on  xmlDocument.Load(txtFileName.Text);
Thanks
       private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog(this) == DialogResult.OK)
{
txtFileName.Text = open.FileName;
treeDocLoadMethod(open.FileName); //this variable gives the name of selected file
bgWorker.RunWorkerAsync();
}
}//Browse button
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
xmlDocument = new XmlDocument();
Thread.Sleep(500);
xmlDocument.Load(txtFileName.Text);
btnBrowse.Enabled = false;
}
private void bgworker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Set progress bar to 100% in case it's not already there.
StripProgressBar.Value = 100;
if (e.Error == null)
{
MessageBox.Show(xmlDocument.InnerXml, "Download Complete");
}
else
{
MessageBox.Show("Failed to download file");
}
// Enable the Browse button and reset the progress bar.
this.btnBrowse.Enabled = true;
StripProgressBar.Value = 0;
toolStripStatusLabel1.Text = "work finished processing request.";
}//workerCompleted

Answers (5)