Need Help in my prorgam [programming C# interop for WORD]

S

Sachin

Hi i have written a program in C# which uses interop and convert Word file
into PDF.
for that i have designed a singleton class which create a word application
once in a lifetime and all future requests uses the same word application.
The program input is directory and it iterate through the directory for each
directory i checks if i already have word application instance created if
not create it else use the same.

Everything works fine until someone externally uses word application
program.
in that case my program start opening the subsequent files into external
word application instead of handling it internally ..

any idea how this should happen ?

here are few snapshots of my program

// Creating Word application
class CWordConverter
{

private Microsoft.Office.Interop.Word.Document currentDocument;
private static CWordConverter instance;
private static Microsoft.Office.Interop.Word.ApplicationClass
wordApplication;


static CWordConverter()
{
instance = null;
wordApplication = new
Microsoft.Office.Interop.Word.ApplicationClass();
wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone;
wordApplication.FeatureInstall =
Microsoft.Office.Core.MsoFeatureInstall.msoFeatureInstallNone;
}

public static void CloseApplication()
{
Object donotsave = WdSaveOptions.wdDoNotSaveChanges;
Object format = WdOriginalFormat.wdOriginalDocumentFormat;
Object missing = Type.Missing;

wordApplication.Quit(ref donotsave, ref format, ref missing);
}
private CWordConverter()
{
}

public static CWordConverter GetInstance()
{
if (instance == null)
{
instance = new CWordConverter();
}

return instance;
}
}

// opening document
currentDocument = wordApplication.Documents.Open(
ref paramSourceDocPath, ref objConfirmConversions, ref
objOpenReadOnly,
ref paramMissing, ref objPasswordtoOpen, ref
objPasswordtoOpentemplate,
ref objRevert, ref ObjWritePasswordDocument, ref
WritePasswordTemplate,
ref paramMissing, ref paramMissing, ref paramMissing,
ref objRepair, ref paramMissing, ref paramMissing,
ref paramMissing);
 
C

Cindy M.

Duplicate question. OP has been pointed to groups more
pertinent. Declines to post elsewhere, as believes question
to be language-neutral. I haven't had time to analyze that
answer.

I disagree, however, that the question is langauge-neutral
as VBA is always running in-process, while C# is automating
the application out-of-process, and that seems to be where
the problem originates.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top