SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried XDocument.View.Window.Close(true); but it tells me "The name 'XDocument' does not exist in the current context"

I even tried thisXDocument.View.Window.Close(true); but still same error.

What other way I can close an Infopath 2010 form using code?

share|improve this question

Here is how i solved this issue

  1. Added a New button and made the Action to be Submit and configured advanced area.
  2. Picked Code based and Copy all my c# code to FormEvents_Submit method
  3. Also added e.CancelableArgs.Cancel = false;

Everything is good with this setup.

share|improve this answer

Moving my answer from closed dupe

From client-side managed code, which is no more than add-on:




are available and work in Infopath Filler Form.

It is not available in Web Browser Form (because it is run through remote Sharepoint Server 2010's Infopath Forms Services).

Here are possible workarounds:

  • setting a bogys submit with a close on submit, calling Submit() from code
  • embedding Infopath form Web Part in ASPX page, closing it from its code

From server-side (external to Infopath code), you should pass a reference to a XML (form) document being closed

share|improve this answer

To close it generally try this:

To close it in the context of a browser:

To get a reference to the form try using the this keyword...

Or try this.Application.Quit() to close the InfoPath application:

share|improve this answer
Actually, I did try all of those links you provided. NONE helped. – Maria Burton Aug 1 '12 at 20:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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