Hilary,
I can't thank you enough. Your C# code for converting an Infopath form to PDF works perfectly. The only problem I have now is that the PDF and XPS conversion loses most of my data and half of the form is cut off.
The only solution I can find is to have the form converted to MHT format. I can do this both manually and by modifying your code to save it to my local drive and it comes out perfectly. But that's not good enough for me. I need to save the converted form to a MOSS SharePoint folder. I can do this fine when I export as a PDF or XPS using your code so I know its not an issue with Full Permission and Signatures as I have those all enabled as necessary.
Here is what I have for exporting as a PDF. This works fine with no errors. I just lose half the information from the form.
//Declare our variables
string fileName;
XPathNavigator nameNode;XPathNavigator nameNode2;
//Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file namenameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager);
nameNode2 = MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:field4", NamespaceManager);fileName = nameNode.Value + "_" + nameNode2.Value +".pdf";
//Do the work -- notice we use the variable fileName as part of the path for the file.
this.CurrentView.Export(@"http://moss.mysharepoint.com/.../mycompletedforms/" + fileName, ExportFormat.Pdf);
Then I try to change a couple of points to convert the form to MHT like this:
//Declare our variables
string fileName;
XPathNavigator nameNode;XPathNavigator nameNode2;
//Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file namenameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager);
nameNode2 = MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:field4", NamespaceManager);fileName = nameNode.Value + "_" + nameNode2.Value +".mht";
//Do the work -- notice we use the variable fileName as part of the path for the file.
this.CurrentView.Export(@"http://moss.mysharepoint.com/.../mycompletedforms/" + fileName, ExportFormat.Mht);
Here are the errors I get.
System.Runtime.InteropServices.COMException
InfoPath cannot export the form.
at Microsoft.Office.Interop.InfoPath.SemiTrust.View.Export(String bstrURL, String bstrFormat)
at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat)
at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format)
at PDF_Test.FormCode.CTRL4_5_Clicked(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Like I said, I can change the export path to my local hard drive and it works perfectly for the MHT export. I can also manually export the form using 'File - Export to.. - Web' and direct it to the SharePoint site and it works perfectly fine that way too. I just need it to work when the button is clicked inside the form.
I certainly appreciate any help that you or anyone can give on this issue.
Thomas Grover
Intel Automation Equipment Specialist