none
Closing a browser based InfoPath form with C#

    Question

  • I have a browser based InfoPath form on which I have a button that when clicked runs some C# code behind it to do various routines like some validation, adding rows to repeating tables and submitting the form.  All of this works as expected, however I also need the form to close after the submit.  I have spent two days trying all sorts of options, none of which work.  Surely there is a way to accomplish this, I just need someone who is more adept at InfoPath to point it out for me?

     

    Thank you in advance for your assistance.

    • Edited by JaeEmAre Friday, November 13, 2009 1:28 PM No longer needed
    Friday, December 28, 2007 1:38 PM

All replies

  • Hi

    You dont need to do it via code. Go to properties of button and change action to "Rules and Custom Code"

    In custom code, you can emit your code and in the rules section, you can add an action which closes the form.

    Madhur
    Sunday, December 30, 2007 12:24 PM
  • Hi

     

    you can do this in 2 ways.

    1. As Madura said adda rule ( get button properties -> add rules -> add action -> select "Close the form")

    2. In FormEvents_Loading method get the url of the previous page

      

          redirectURL = HttpContext.Current.Request.UrlReferrer.OriginalString.ToString();

     

        and in the button Clicked method 

         HttpContext.Current.Response.Redirect(redirectURL.ToString(), false);

     

     

    Friday, January 04, 2008 12:06 PM
  • thanks ,
    but i am not able to write this code bcz  it give build error

    string  edirectURL =   HttpContext.Current.Request.UrlReferrer.OriginalString.ToString();


    Error    2    The name 'HttpContext' does not exist in the current context    F:\Projects\Current Projects\Eicher\CodefileofIDPR\Appraisal\FormCode.cs    94    36    Appraisal



    may i have to add any extra name space

    Wednesday, March 05, 2008 12:48 PM
  • Hi,

     

    Yes because you have to add namespace "using System.Web" in your code.

     

    The name "httpcontext" comes under this namespace only.

     

    and one more thing you have to do is, use System.Web.UI.Page with your partial class ..........

     

    public partial class FormCode : System.Web.UI.Page

     

    [=Amit]

     

    Wednesday, March 05, 2008 1:37 PM
  • hi ,
    i wrote those code it give no error on build but when i run i give me error of "object reference error"
    Thursday, March 06, 2008 4:16 AM
  • Janet,

     

    I think Madhur Ahuja  is on the right path.  I faced a similar question and did it this way.

     

    1. Set the Submit Option to "Perform custion action via Code", and set the Advanced "After Submit" property to "Close the Form"
    2. Code the FormEvents_Submit .  For the submit to the form library to work you need to use the FileSubmitConnection related code.

    Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
                ' If the submit operation is successful, set e.CancelableArgs.Cancel = False
                ' Write your code here.
                Dim lb_Success As Boolean = False
                Dim fc As FileSubmitConnection
                Try
                    Me.of_SomePreSaveFunction()
                    fc = DirectCast(Me.DataConnections("SharePoint Library Submit"), FileSubmitConnection)
                    fc.Execute()

                    e.CancelableArgs.Cancel = False 'success
                    lb_Success = True
                Catch ex As Exception
                    e.CancelableArgs.Cancel = True 'Error
                    of_ErrorMessageFunction("Error Submiting the form - FC Execute Error: " + ex.Message, False)

                End Try

                If lb_Success Then
                    ' any other non-critical processing
                    of_SomeCleanupFunction()
                End If

                fc = Nothing

            End Sub

     

    3. Finally, add a button with the Action property set to Submit, which will use your code.

    Friday, March 07, 2008 4:04 PM
  • hi actually i tried with this same  things  with programming but i can't . Thats why i do something different .

      As i create a view with button to close. And after my code complete just switch the view .

    And u can also add a rule to close the form .It auto matically close the form but validation can't be checked

    pradipta nayak
    Friday, July 25, 2008 9:42 AM
  • Hi Janet,


      it fine i use this its fine, but problem i face code is

     if (MainNav.SelectSingleNode("/my:myFields/my:field1", NamespaceManager).ToString().Contains("P") == true)
                    {
                        e.CancelableArgs.Cancel = false;
                    }
                    else
                    {
                     
                            e.CancelableArgs.Cancel = true;
                           
                        }



    but when the  condition get false then  it give an Warning message as i place the code in try and catch block.

     i don't want to show the warning message..

    Warning message is





    Warning
    Powered by:
    There has been an error while processing the form.
    Click Continue to resume filling out the form. You may want to check your form data for errors.
    Click Start Over to load a new copy of the form.
    Hide error details
    xxx
    yyy


    Thanks and Regards Er.Pradipta Nayak
    Saturday, February 28, 2009 9:25 AM
  • hi Janet,

    i am waiting for ur replay please help .Thanks in advance....
    Thanks and Regards Er.Pradipta Nayak
    • Proposed as answer by Firoz Pathan Wednesday, April 01, 2009 9:06 PM
    • Unproposed as answer by Mike Walsh FIN Monday, May 04, 2009 10:37 AM
    Thursday, March 26, 2009 7:22 AM
  • Hello Dera

    I used your solution but it didn't work , this is my code:

    public partial class FormCode:System.Web.UI.Page


    ....

    System.Web.HttpRequest.Current.Response.Redirect

                            ( System.Web.HttpContext.Current.Request.UrlReferrer.OriginalString);

     

    - after using inheritance this error occured :

    Error 1 Missing partial modifier on declaration of type 'SubmitTemplate.FormCode'; another partial declaration of this type exists  ....\InfoPath Projects\SubmitTemplate1\FormCode.cs 8 26 SubmitTemplate

    - without using inheritance i got "object reference error".

    i add system.web as refrences too.and my form is brwser-enabled .could you help me to solve this ?

    actually :
    ,I have a button in form and i handle click event for that (in code) to save in My sharepoint Document Library.(it works well)

    so after saving without error, i want to close form (i cannot use a Close Rule for that , because it occurs before click event) 

    or redirect it to Document Library (this part is the problem ),
    I should add my form is browser enabled, too. and jscript it's not work

    although i test thease code too, and did not work when i publish form to sharepoint :

    1- System.Diagnostics.

    Process.Start("iexplore.exe", URL);

    2- System.Web.HttpRequest.Current.Response.Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.OriginalString);

    please help me how i can solve it?



    ....


    Thursday, October 29, 2009 6:37 AM