In infoPath form I have a button which duty is to print the current document, I have been trying this one thisXdocument.PrintOut(); but the following error occurs "The name "thisXdocument" does not exist in the current context".

Is there anyone who can help me?


If you can use Javascript, there is workaround. You can take out the content wrapper part and create a new window (or use same window) and call window print functionality.

Following is the code you can use (on same window)

    function printDocument(wrapperId){
        var printContent = $(wrapperId).html();
        var orgContent = $('body').html();

        // Put print content in body, so we can take window print advantage.
        // Put original content back in body so after print, the page look as it was before.

<input type='button' onclick="printDocument('#printSection')" value="Print" />

Just replace the #printSection with the wrapper ID of your print section.


You can follow these steps for that,

1) Paste “XDocument.PrintOut()” under the code of Print button you placed. 2) Give full trust to your form and sign it. 3) Now publish the form either to sharepoint or localdirectory. 4) Open the published form and click that Print button . 5) A dialog will be displayed asking you to save that file with an extension “mdi”. 6) Click on save and you will see the print preview of that form. 7) You can now do whatever you want regarding printing.

  • the following error says: The name "thisXdocument" does not exist in the current context.! what should I do? – Nderon Hyseni Dec 18 '15 at 8:40
  • Use XDocument.PrintOut() instead of thisXdocument.PrintOut(). – Pravin Dec 18 '15 at 8:42
  • i added this reference /using System.Linq; but .PrintOut() in not valid which reference should I add? – Nderon Hyseni Dec 18 '15 at 8:48
  • Try this option too--> To add Print button in the Form, you can add a content editor web part to print the page. Edit the HTML source for the content editor web part to add the print button: <input type="button" value=" Print this page "onclick="window.print();return false;" />. – Pravin Dec 18 '15 at 8:56
  • thank but i have to do it via button in infopath form only but thanks anyway – Nderon Hyseni Dec 18 '15 at 8:57

You cannot use XDocument in InfoPath 2010 or later. Instead, you can use this.Print() method. This will print current page directly to default printer (unfortunately no dialog will pop up).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.