Vasanth Krishnan

Vasanth Krishnan

  • NA
  • 113
  • 54.5k

Comman Failed Error in doc.saveas method.

Jul 24 2013 2:26 AM

Hi

I am trying to convert doc to pdf using the following code.


public void ConvertPdf()
  {
      object sFilename = "Report5.doc";
      object FromLocation = Server.MapPath("~/Form5/" + sFilename.ToString());
      string ChangeExtension = sFilename.ToString().Replace(".doc", ".pdf");
      object ToLocation = Server.MapPath("~/Form5PDF/" + ChangeExtension);
 
      //string ConvertResult = word2pdf.Word2PdfCOnversion(FromLocation, ToLocation);
 
      Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
 
      object oMissing = System.Reflection.Missing.Value;
 
      word.Visible = false;
      word.ScreenUpdating = false;
 
      Document doc = word.Documents.Open(ref FromLocation, 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 fileFormat = WdSaveFormat.wdFormatPDF;
 
      doc.SaveAs(ref FromLocation,
      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);
 
      object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
      ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
      doc = null;
}

In that line doc.SaveAs, i am getting the error Command failed error. I am using microsoft visual web developer tool to develop the site.

Hope this is clear. Please let me know if this is not.

Thanks.

Answers (1)