Convert InfoPath to PDF issue RRS feed

  • Question

  • Hi All,

    I have written a code to convert InfoPath form (.xml) to PDF through code. I have deployed this as a webpart in an SPS 2007 site, where there is a button to "convert". This code works well when I run it as standalone web application( out of SharePoint ). But when I tried it through Sharepoint, it doesn't work. The code sample is given below



    Microsoft.Office.Interop.InfoPath.Application app = new Microsoft.Office.Interop.InfoPath.Application();
    Microsoft.Office.Interop.InfoPath.XDocument xDoc = app.XDocuments.Open("http://MyWebSite:3333/MyLibrary/TEST1.xml", (int)Microsoft.Office.Interop.InfoPath.XdDocumentVersionMode.xdCanOpenInReadOnlyMode);
    xDoc.View.Export(@"http://MyWebSite:3333/Converted%20PDF/exported1.pdf", "PDF");

    The error is in line #2 (when I try to open the doc). At that line, while debugging, nothing happens. it just losses focus from there and the page will wait for ever.

    Any help is appreciated.




    Wednesday, June 22, 2011 6:55 PM

All replies

  • Hi Sarath,

    Based on my testing, if the version mode is xdCanOpenInReadOnlyMode, we will encounter the error:
    The form is an older version than the current form template.

    To fix the issue, please use mode xdFailOnVersionOlder instead.

    Jinchun Chen

    Jinchun Chen Forum Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Tuesday, June 28, 2011 9:19 AM
  • Thanks for the reply!

    I believe that error is because of the XML version doesn't match the XSN. I didn't get that error over here. Did you try deploying your solution as an ISS web site or as a Sharepoint webpart/ webpage? 

    I think that the Interop dll is not meant to be used in the Web Server environment. This could be some access issue of AppPool account or something. 


    I tried the following stuff and failed


    1) SPSecurity.RunWithElevatedPrevilages

    2) Impersonation

    3) Given "NETWORK ACCOUNT" access to the InfoPath installed folder location


    Please let me know if you have any updates...


    Tuesday, June 28, 2011 3:55 PM