I intent to load a word document into a richtextbox.
I have the below code. Which yes is working, but it is taking waaaay to long to load.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Word Documents|*.doc; *.docx";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object path = ofd.FileName;
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly,
ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int i = 0; i < docs.Paragraphs.Count; i++)
{
totaltext += "\t " + docs.Paragraphs[i + 1].Range.Text.ToString();
}
richTextBox1.Text = totaltext;
}
It takes about 2 mins to load a 3 page test document, and foreer to load a 60+ page document.
It might have something to do with the for loop. Kindly assist me with a way to IMPROVE ON THE SPEED.