Friday, December 2, 2011

How to redirect Infopath form to different site collection programmatically?

It's much harder than what it looks like.

At first, I thought it could be done by HttpContext.Current.Response.Redirect(), however, this is supported only if the destination page is in in "Internet Zone" (for IE).

Then, I tried SPUtility.Redirect(), and got the same result.

What about the "Source" query string? It works, but if you want to jump to another site collection, this error message will pop up: "The following location is not accessible, because it is in a different site collection".

Can we insert Javascript into InfoPath form?  No!


After hours of investigation, finally, I realized I was asking wrong question.   The correct one is:  How to utilize InfoPath web form in different site collection?  That is easy!

With the help of some javascript function, we can paste the script below to a Content Editor Web Part.  This CEWP can be inserted into any site collection of the same farm.

(This sample code also shows how to pass query parameter to InfoPath form)

<script language="javascript">
function getQuerystring(key, default_) 

    if (default_==null) 
    var search = unescape(; 
    if (search == "") 
        return default_; 
    search = search.substr(1); 
    var params = search.split("&"); 
    for (var i = 0; i < params.length; i++) 
        var pairs = params[i].split("="); 
        if(pairs[0] == key) 
            return pairs[1]; 
    return default_; 

function OpenIPFormDialog()
var options = SP.UI.$create_DialogOptions();
options.url = 'http://' + window.location.hostname + '/sites/IPForm/Site1/_layouts/FormServer.aspx?XsnLocation=/sites/IPForm/FormServerTemplates/IPForm1.xsn&DefaultItemOpen=1&accountname=' + getQuerystring('accountname');
options.allowMaximize = true;
options.autoSize = true;
options.showClose = true;
<a href="#" onclick="javascript:OpenIPFormDialog()">Change User Information</a>

No comments:

Post a Comment