0

I'm creating an InfoPath form in InfoPath 2010 Designer, that will be running in InfoPath 2007 and 2010 clients and contains C# code.

When the user clicks the submit button I need to execute some C# code, then submit and close. I can add the submit to the C# code, but closing the form seems only possible from a rule (which whould execute before the code).

I found and tried a hint, to configure the form to close automatically after the submit, but somehow this isn't working. Are there other ideas?

1 Answer 1

2

You should be able to simply add the following to your C# code...no need for a rule or the "close automatically after submit" form setting.

XDocument.View.Window.Close(true); 

Hope that helps.

EDIT: My apologies...I gave you a method for scripting the close, that object is not accessible via C#. I was able to setup a form where the submit executed some C# code and set the "After Submit" option to "Close the form" and it worked fine for me.

enter image description here

Is this what you tried that didn't work?

4
  • Thanks for the quick answer. Intellisense can't find XDocument, which Assembly do I have to reference? This isn't the Lync class XDocument, is it? Because I can't find a View property in that one...
    – Hinek
    Jul 27, 2011 at 13:51
  • Sorry, I don't get it, your code sample looks, like View is a static property of XDocument. But the msdn link says, XDocument is an interface, so it can't have static properties. How can I get an instance of XDocument for my current form?
    – Hinek
    Jul 27, 2011 at 15:13
  • Hey thanks, now it is working. Yes this was what I tried, but I didn't use "Perform custom action using Code". I used the "Send form data to a single destination" and had the form code behind a button. At the end of the code I called this.Submit(), expecting it to trigger the settings from this dialog. But it didn't. Now with the code in the submit options, it is working :D
    – Hinek
    Jul 28, 2011 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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