Thursday 15 September 2011

c# - Getting System.Runtime.InteropServices.COMException: Command failed -



c# - Getting System.Runtime.InteropServices.COMException: Command failed -

i have used microsoft.office.interop.word converting word pdf, working fine on local machine.

but when moved exe files server (server has microsoft office installed), it's showing me below exception.

unhandled exception: system.runtime.interopservices.comexception: command failed @ microsoft.office.interop.word.documentclass.saveas(object& filename, objec t& fileformat, object& lockcomments, object& password, object& addtorecentfiles, object& writepassword, object& readonlyrecommended, object& embedtruetypefonts, object& savenativepictureformat, object& saveformsdata, object& saveasaocelette r, object& encoding, object& insertlinebreaks, object& allowsubstitutions, objec t& lineending, object& addbidimarks) @ pdf_converter.program.convertwordtopdf(string sinputfile, string soutputfi le) in d:\work\htmltopdf_converter\html_pdf_converter\image_pdf_converter\progra m.cs:line 89 @ pdf_converter.program.main(string[] args) in d:\work\htmltopdf_converter\h tml_pdf_converter\image_pdf_converter\program.cs:line 30

below code conversion.

private static void convertwordtopdf(string sinputfile, string soutputfile) { // create new microsoft word application object microsoft.office.interop.word.application word = new microsoft.office.interop.word.application(); // c# doesn't have optional arguments we'll need dummy value object omissing = system.reflection.missing.value; word.visible = false; word.screenupdating = false; if (file.exists(sinputfile)) { fileinfo wordfile = new fileinfo(sinputfile); // cast object word open method object filename = (object)wordfile.fullname; // utilize dummy value placeholder optional arguments microsoft.office.interop.word.document doc = word.documents.open(ref filename, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing); doc.activate(); object outputfilename = soutputfile; object fileformat = wdsaveformat.wdformatpdf; // save document pdf format doc.saveas(ref outputfilename, ref fileformat, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing, ref omissing); // close word document, leave word application open. // doc has cast type _document find // right close method. object savechanges = wdsaveoptions.wddonotsavechanges; ((_document)doc).close(ref savechanges, ref omissing, ref omissing); doc = null; } // word has cast type _application find // right quit method. ((_application)word).quit(ref omissing, ref omissing, ref omissing); word = null; }

is there i'm missing?

i getting same error mentioned.

check if office installed on server have pdf type in "save as" options?

install 2007 microsoft office add-in: microsoft save pdf or xps below link if not available.

http://www.microsoft.com/en-in/download/details.aspx?id=7

i hope resolve error.

c# com ms-word office-interop

No comments:

Post a Comment