Currently, I'm using this code to get the list of MS Word opened documents:
List<string> doc_list = new List<string>();
try
{
Microsoft.Office.Interop.Word.Application WordObj;
WordObj = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
for (int i = 0; i < WordObj.Windows.Count; i++)
{
object idx = i + 1;
Window WinObj = WordObj.Windows.get_Item(ref idx);
doc_list.Add(WinObj.Document.FullName);
}
}
catch
{
// No documents opened
}
And it correctly works if the documents have been opened "directly", i.e. by double clicking on them. However, I noticed that if I open a MS Word document directly from C# code, like:
Microsoft.Office.Interop.Word.Application word_app = new Microsoft.Office.Interop.Word.Application();
object inputFile = selected_doc; // "selected_doc" contains the document name
object confirmConversions = false;
object readOnly = false;
object visible = true;
object missing = Type.Missing;
Document doc = word_app.Documents.Open(
ref inputFile, ref confirmConversions, ref readOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref visible,
ref missing, ref missing, ref missing, ref missing);
any document opened in this way is not found by the intial code, but I need to detect it. Why is it not found? How can I modify the code so that the document opened from C# will be found?