0

i am trying fetch data from word document using

string Mainer(string pathfile)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

                object miss = System.Reflection.Missing.Value;
                object path = pathfile;
                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 += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
                }

                docs.Close();   
                word.Quit();
                word = null;
                docs = null;
                GC.Collect(); 
                return totaltext;
        }

i get error The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) i using this code in foreach any suggestion for this error ?

Eng Mohamed Attian
  • 97
  • 1
  • 2
  • 10
  • Which line of code throws the error? –  May 11 '15 at 14:39
  • I've run that in a loop with the same file - no problems. This may be specific to you version of Word, add-ins you have installed etc. – Charles Mager May 11 '15 at 14:42
  • 1
    `docs.Close(); word.Quit();` you need to understand how to dispose of Interop objects.. look up on line the following `System.Runtime.InteropServices.Marshal.ReleaseComObject` and here is a link that you can follow asa well do not use `GC.Collect` it's not guaranteed under theses circumstances. http://stackoverflow.com/questions/6777422/disposing-of-microsoft-office-interop-word-application – MethodMan May 11 '15 at 14:47

0 Answers0