Hi Everyone,
I am struggling since last 3 days and i googled every where to solve this issue..
public bool SaveDocument(object objWordOutputPath, string strOutputFolder)
{
try
{
object objMissing = System.Reflection.Missing.Value;
object objOutputFileName = objWordDoc.FullName.Replace(".doc", ".pdf");
object objFileFormat = WdSaveFormat.wdFormatPDF;
objWordDoc.SaveAs(ref objOutputFileName,
ref objFileFormat, ref objMissing, ref objMissing,
ref objMissing, ref objMissing, ref objMissing, ref objMissing,
ref objMissing, ref objMissing, ref objMissing, ref objMissing,
ref objMissing, ref objMissing, ref objMissing, ref objMissing);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
return true;
}
catch (Exception ex)
{
CloseDocument();
Logger.LogFormat("Error mesaage:-->" + ex.Message);
Logger.LogFormat("Error mesaage:-->" + ex.StackTrace);
objWordDoc = null;
return false;
}
}
As i written code to generate pdf file form word document its working fine in my local desktop and i generated an ".msi" for this code snippet.
I had installed it on Windows server 2008 R2 when i run the ".exe" i got an error saying that...
("Command Failed" and "at Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)")
Office version 2007, Visaul Studio 2010 and Windows server 2008 R2.
Could you please help me out to solve this issue....
Regards,
Dilip.
Nitesh KejriwalPosted Sep 3, 2013, 3:09 AM
If your code is working locally, it should work on server OK as well.
Check which user is executing the application and then ensure the folder where the code is writing has read/write privilege to the user.
In case of ASP.Net, we use impersonation to allow IIS to write word files to the server.
Regards,
Nitesh.
Gunti DilipPosted Sep 3, 2013, 1:35 AM
The code which i written is it fine or do i need to change any coding part.
Is there any other way to generate .pdf form .doc by providing privileges to read/write to the location on server through code ?
Regards,
Dilip.
Nitesh KejriwalPosted Sep 2, 2013, 11:08 PM
1. Please check the assembly is registered in GAC. (I think it is already in your case)
2. Ensure you have proper privileges to read/write to the location on server.
3. Ensure the user who is running the software has enough privileges on server to do so.