none
How to redirect Infopath form programmatically on button click

    Question

  • I am having an issue with infoPath Forms and C#, 
    I have a 1st form open to the user, and when he click a button it opens a 2nd form.

    Sounds pretty easy, but I have tried many ways and still error.
    (environment is InfoPath Forms 2007 in Sharepoint and code: C#)

    this is what I have:
    - form1 . a text field where I enter the URL of form2
                . a button with code below

    The issue is that if I type the URL of form2 
    (http://sharepointserver/sites/MySiteCol/Myinfopath/_layouts/FormServer.aspx?XsnLocation=http://sharepointserver/sites/MySiteCol/FormServerTemplates/form2.xsn&SaveLocation=http://sharepointserver/sites/Myinfopath/InfoPathLib)
     in the text field and press the button I get this error
    "Critical Error : An error occurred submitting this form to the Web server. The form will now be closed."

    But instead of the URL of form2.xsn I type http://www.google.com/ they it works (well except the image somehow, but that's not the problem)

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using System.Web;
     // get the text field entry
    string out_URL  = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:textURLField", NamespaceManager).Value;
    // now go to that URL
    HttpContext.Current.Response.Redirect(out_URL  , false); --> is not working for complex address, but works for simple domain (http://google.com/)

    PS: form1 & form2 are both Forms compatible + FullTrust security.

     

    • Edited by Mike Walsh FIN Thursday, April 08, 2010 3:22 AM Shouting removed
    Wednesday, April 07, 2010 8:10 AM

Answers

  • Hi,

    I do not realy understood your case but if you look at a default url, created after you click on a "new" button in a formlib you will se a further parameter "...&Source=....". this parameter contains the url which will be navigate to after the form is submitted.

    if you want to open a second form without submitting the first one. I will do it  by a Hyperlink in the form1.

    crate a field of type string in your Main Datasource which will store the url. Update this field, with full url to the form2, in your OnLoad mehtod of Form1. so the user will click on a link, and everything should work fine.

    hope this helps

    bg Andrej

    • Marked as answer by Stanfford Liu Friday, April 16, 2010 9:29 AM
    Wednesday, April 07, 2010 2:27 PM
  • i prefer to use hyperlinks in such cases.

    bg Andrej Salnik

    • Marked as answer by Stanfford Liu Friday, April 16, 2010 9:29 AM
    Thursday, April 08, 2010 6:47 PM

All replies

  • Hi,

    I do not realy understood your case but if you look at a default url, created after you click on a "new" button in a formlib you will se a further parameter "...&Source=....". this parameter contains the url which will be navigate to after the form is submitted.

    if you want to open a second form without submitting the first one. I will do it  by a Hyperlink in the form1.

    crate a field of type string in your Main Datasource which will store the url. Update this field, with full url to the form2, in your OnLoad mehtod of Form1. so the user will click on a link, and everything should work fine.

    hope this helps

    bg Andrej

    • Marked as answer by Stanfford Liu Friday, April 16, 2010 9:29 AM
    Wednesday, April 07, 2010 2:27 PM
  • Hi Andrej,

     

    Thanks for the Reply!

     

    I have a slight change in requirement. Could you help please..

    I am trying to open up a Report(SSRS) from Infopath form on button click. the url i am using is as follows.

    string strurl = "http://server2:8080/ReportServer_sqlserver23?/CoreProduct&rs:Command=Render&rs:Format=PDF&ReportParameter=http://testserver/personal/ThortonRoss/test1/IMBLatestDocs/test1.xml?noredirect=true";

    After this code executes, a warning message from IE comes up saying 'this page is tryong to access information that is not under its control. It poses a security risk.Do you want to continue?'

    When i click on yes, i get 'Critical Error' pop up with the options 'Start Over' and 'Exit'

    Other url's like 'http://www.yahoo.com/latest-news.html', 'http://www.google.com' opens up properly from Infopath form itself on button click.

    However the same above url 'strurl' opens up the PDF correctly when i enter this url directly in to the browser.

     

    Any sort of help would be appreciated !

     

    Ritesh

    Thursday, April 08, 2010 4:39 AM
  • i prefer to use hyperlinks in such cases.

    bg Andrej Salnik

    • Marked as answer by Stanfford Liu Friday, April 16, 2010 9:29 AM
    Thursday, April 08, 2010 6:47 PM
  • Thanks Andrej my hyperlink works on infopath with the trick you mentioned.

     

    Wednesday, September 22, 2010 12:43 PM
  • Hi All, I have this exact same problem. When submitting my form, after the submit event I am using HTTP Redirect to change to another, complex.. When I set it to change to google.com, it works fine. But when I set it to a long, complex address, I get a form error. Any solutions?
    Thursday, November 25, 2010 7:53 AM
  • Is it not possible for you to modify the "&Source=" property in your query string before the form is opened?

    if you can put your destination of redirection in the query string, sharepoint will manage it for you automatically.

    bg Andrej

    Friday, November 26, 2010 9:22 AM
  • I can modify the source Andrej, but the problem is that I need it to be dynamic. The form should redirect to slightly different URL's based on what the user enters in the form.

    Basically, upon submitting the form, the user should be redirected to a seperate newform.aspx page. On this page I have implemented some custom javascript to take in query parameters and automatically populate the form fields.

    For example, newform.aspx?Title=New&Description=NewUser will automatically set the Title and description fields.

    This is my code:

           Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
                Dim spConn As DataConnection = DataConnections("Main submit")
                spConn.Execute()
                e.CancelableArgs.Cancel = True
                Dim mainNav As XPathNavigator = Me.CreateNavigator
                Dim first As String = mainNav.SelectSingleNode("/my:newEmployee/my:employee/my:firstName", NamespaceManager).Value
                Dim last As String = mainNav.SelectSingleNode("/my:newEmployee/my:employee/my:lastName", NamespaceManager).Value
                Dim fullName As String = first + last
                Dim rURL As String = String.Empty
                rURL = "http://intranet.mundaring.wa.gov.au/corporate/INFORMATION%20TECHNOLOGY/Lists/Helpdesk/NewForm_Request.aspx"
                Dim finalURL As String = String.Empty
                finalURL = String.Concat(rURL, "?Item%20Description=", fullName)
                HttpContext.Current.Response.Redirect(finalURL, False)

    And when it runs it simply throws an error. It does submit, just can't redirect. If I use http://www.google.com instead of finalURL, it redirects fine... 

    Monday, November 29, 2010 3:48 AM
  • I have more information relating to this problem.

     

    It seems the use of HttpContext.Current.Response.Redirect works perfectly, when the URL it is going to is in the Internet Zone.

    I only experience InfoPath form errors when trying to redirect to a site that is part of my Local Intranet Security Zone.

    For example, I am trying to redirect from a form on my intranet, to another form on my intranet, and it is throwing an error. Redirecting to an external site, (ANY), works perfectly...

    Wednesday, December 01, 2010 4:45 AM
  • Hello!  I know this is an old thread.  But I am having a difficult time figuring out how to do this.  I have an web enabled InfoPath form.  After it's completed, I submit to a library, but I also gererate a dynamic url, which I need to redirect the user either on button click or using the hyperlink.  The hyperlink works great, EXCEPT it opens in a new browser tab.  This is not acceptable.  How can I open in the same window OR close the form tab when it goes to the new url?

    thanks!

    Friday, March 07, 2014 6:42 PM