Saturday, September 13, 2008

reading word content into the text box

I think may be u tried all interop combinations to read word document ,
But where everything fails is eveytime u instantiate word app a new process will be created under asp.net account but whenever we are closing the document the process wont stop that’s y a loop will be formed and whenever we are running the same application we cant instantiate another instance for wordapp

By placing this code it is working fine for me (upto now)

So have a look on this





try
{
string strfilePath = ds.Tables[0].Rows[0]["ResumePath"].ToString();

Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object nullobj = System.Reflection.Missing.Value;
object FileObj = strfilePath;
Microsoft.Office.Interop.Word.Document Doc = WordApp.Documents.Open(ref FileObj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
Microsoft.Office.Interop.Word.Document Doc1 = WordApp.ActiveDocument;
string m_content = Doc1.Content.Text;
txtResume.Text = m_content;
Doc.Close(ref nullobj, ref nullobj, ref nullobj);
WordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
WordApp = null;
Doc = null;
Process p = Process.GetCurrentProcess();

p.Close();
}
catch
{
throw;
}

No comments: