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);
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);