A
Andrew
Hello, friends,
This may not belong here, but I could not find the proper group.
In c#.net 2005, we use office interop to start different .doc files. The
source code are as the follows:
object fileName = fullPathFileName;
object newTemplate = false;
object docType = 0;
object isVisible = true;
if (wordApp != null && wordApp.Documents != null)
{
Microsoft.Office.Interop.Word.Document doc =
wordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref
isVisible);
wordApp.Visible = true;
}
The above worked for the first document opening without problem.
What we want to do is: We need to check if the next given fullFileName is
already open. If yes, we just bring it to front, rather than to open a
duplicate one. Otherwise, open it using above code. The source code for this
checking are like the follows:
if (wordApp != null)
{
foreach (Microsoft.Office.Interop.Word.Document doc in
wordApp.Documents)
{
if (String.Compare(doc.FullName, fullPathFileName,
true) == 0)
{
doc.Activate();
return;
}
}
}
However, we found the doc.FullName had the value Document1 for the first
open .doc file, therefore, failed the checking, and always caused a
previously given fullFileName being opened again.
Any ideas, reference paper or snippet? Thanks a lot!
This may not belong here, but I could not find the proper group.
In c#.net 2005, we use office interop to start different .doc files. The
source code are as the follows:
object fileName = fullPathFileName;
object newTemplate = false;
object docType = 0;
object isVisible = true;
if (wordApp != null && wordApp.Documents != null)
{
Microsoft.Office.Interop.Word.Document doc =
wordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref
isVisible);
wordApp.Visible = true;
}
The above worked for the first document opening without problem.
What we want to do is: We need to check if the next given fullFileName is
already open. If yes, we just bring it to front, rather than to open a
duplicate one. Otherwise, open it using above code. The source code for this
checking are like the follows:
if (wordApp != null)
{
foreach (Microsoft.Office.Interop.Word.Document doc in
wordApp.Documents)
{
if (String.Compare(doc.FullName, fullPathFileName,
true) == 0)
{
doc.Activate();
return;
}
}
}
However, we found the doc.FullName had the value Document1 for the first
open .doc file, therefore, failed the checking, and always caused a
previously given fullFileName being opened again.
Any ideas, reference paper or snippet? Thanks a lot!