Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

3 Answers 3

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

To close it generally try this: http://stackoverflow.com/questions/127572/how-do-i-programmatically-close-an-infopath-form-in-c

To close it in the context of a browser: http://social.msdn.microsoft.com/forums/en-US/sharepointinfopath/thread/d0ecbadb-ee93-4016-bbad-fe70eddc095e/

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

Or try this.Application.Quit() to close the InfoPath application: http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.application.quit%28v=office.11%29

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

Moving my answer from closed dupe

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

Application.Quit();

and

this.Close();

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

Your Answer

 
discard

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.