Hi! I used ProgressBar in bellow code, but it’s not worked. Who is you can help me?
private void btn_Click(object sender, EventArgs e)
{
progressBar1.Minimum = 0;
DialogResult secnDoc = openseconDoc.ShowDialog();
if (secnDoc == DialogResult.OK)
{
string filesecnDoc = openseconDoc.FileName;
string[] filePaths = System.IO.Directory.GetFiles(@"C:\Documents\");
foreach (string filefirstDoc in filePaths)
{
if (filefirstDoc.Contains(".doc") || filefirstDoc.Contains(".docx"))
{
CompareWordFile(filefirstDoc, filesecnDoc);
}
}
}
}
public void CompareWordFile(string fileToCompare, string fileToChange)
{
Microsoft.Office.Interop.Word.Application fwrd = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Application swrd = new Microsoft.Office.Interop.Word.Application();
Document fdoc = new Document();
Document sdoc = new Document();
object missing = System.Type.Missing;
object fn = fileToCompare;
object sn = fileToChange;
fdoc = fwrd.Documents.Open(ref fn, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
sdoc = swrd.Documents.Open(ref sn, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
string temp = string.Empty;
for (int i = 0; i < fdoc.Paragraphs.Count; i++)
{
temp += fdoc.Paragraphs[i + 1].Range.Text.Trim();
}
ndup = sdoc.Sentences.Count;
progressBar1.Maximum = ndup;
string[] firstFile = temp.Replace(":", "").Replace("?", "").Replace("!", "").Replace(",", "").Replace("-", "").Replace(";", "").Trim().Split('.');
for (int i = 0; i < firstFile.Length - 1; i++)
{
string item = firstFile[i];
foreach(Microsoft.Office.Interop.Word.Range docRange in sdoc.Sentences)
{
if (docRange.Text.Replace(":", "").Replace("?", "").Replace("!", "").Replace(",", "").Replace("-", "").Replace(";", "").Split('.')[0].Trim().Equals(item.Trim(), StringComparison.CurrentCultureIgnoreCase))
{
docRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
dup = dup + 1;
}
}
progressBar1.Value = Convert.ToInt32(((double)dup/(double)ndup) * 100);
}
sdoc.Save();
((_Application)fwrd).Quit();
((_Application)swrd).Quit();
}