Monday, December 9, 2013

Migrate browser based InfoPath Forms with code behind from MOSS 2007 to SharePoint 2013

What?

How to successfully migrate browser based InfoPath Forms with code behind from MOSS 2007 to SharePoint 2013?

In this post I will try to explain some of the obstacles that you might be hit with and the ways to get around them.

Please use this is a general guide to understand the overall migration process.


Why?

InfoPath forms migration has always been a pain. Every version of InfoPath is different from its previous version.

Unless third party tools like AvePoint’s DocAve Migrator are used for migration, there is no direct path from MOSS 2007 to SharePoint 2013. The web applications that are required to be migrated will first have to be migrated to SharePoint 2010 and then to SharePoint 2013.

With InfoPath forms that contain code behind however, no tool can help you. You will have to rebuild and redeploy the InfoPath form solution even if you use third party tools.

In my scenario, I had to migrate browser based InfoPath forms that were built in InfoPath 2007 with custom code behind into SharePoint 2013.

I am totally against and would not recommended writing code behind with InfoPath forms at all but I had to migrate and support the forms that are already being used.

How?

The first step is to migrate all the content from MOSS 2007 to SharePoint 2010.

Migrate content from MOSS 2007 to SharePoint 2010:

Perform the migration of the content from MOSS 2007 farm to the SharePoint 2010 farm first. I have used Database Attach method to mount the content databases.

Rebuild the InfoPath Form Template in InfoPath 2010:

  • Find the InfoPath form template and open it in design mode
  • Go to File > Form Options > Security and Trust and ensure that the security is set to full trust and that the form template is signed.
  • If the InfoPath template does not have any data connections, we can go ahead and publish the .XSN form into a network location (Make sure to leave the path in the second dialog as empty)
  • If the InfoPath template contains any data connections, follow the procedure below:
  • Go to File > Publish > Export Source Files and save the files.
  • Go to the location where the source files are saved. Find the file “manifest.xsf” and edit it in note pad or your favourite editor. Find and replace all the references to old site url with the new site url and make a note of all the data connections.
  • Publish the manifest file as a .XSN form

Building the Visual Studio 2010 solution to deploy the InfoPath form:

Dr. Nader has posted a great article explaining the process of deploying an InfoPath form with code behind here with source files as well.

Create/use Nader's Visual Studio solution and copy the form into the visual studio solution, rename the elements as needed, rebuild the VS solution and deploy it.

Important: Ensure that the feature that deploys the xsn form is deployed in CA

Download all the data connections that you have renamed while rebuilding the form. Update all of them to point to the correct site. Upload them back to the data connection library and overwrite the old data connections.

If the visual studio solution is deployed correctly, you will see 2 farm solutions listed in the solution store.

1.) The farm solution that was deployed by the visual studio solution
2.) Another solution in the format “form-{InfoPath Form Template name}”.wsp which is added dynamically

The second solution will be installed and deployed dynamically by the feature receiver in the visual studio solution. If the second solution is not found in the solution store, that indicates that the form template deployment failed. Try to correct the issue and redeploy it until the second solution is deployed.

After the dynamic farm solution is successful deployed, go to Central Administration > General Application Settings > Manage Form Templates. You should see the InfoPath form template listed in the list of form templates. Pick the form template and activate it in the desired site collection.

Go to Site Collection settings in the site collection in which the form template is activated and go to site collection features.

You will see a feature with the same name of the InfoPath form template. Activate it. Verify that the form template is installed correctly by navigating to the url: http://{site collection url}/ /FormServerTemplates/Forms/All%20Forms.aspx

Now navigate to the library in which the InfoPath forms reside and open an existing form/create a new form. If you are lucky enough, the forms should open without any errors.

Migrate content from SharePoint 2010 to SharePoint 2013:

Perform the migration of the content from SharePoint 2010 farm to the SharePoint 2013 farm. I have used Database Attach method to mount the content databases.

If you have no need to continue with the InfoPath form development in SharePoint 2013, you might just go ahead and install the wsp file in SharePoint 2013 and the InfoPath forms might work. But if you think that there will be a need to continue to support/work with the InfoPath form template(s), follow the below to upgrade the InfoPath form template to InfoPath 2013.

Upgrading the InfoPath form solution from SharePoint 2010 to SharePoint 2013:

Open the solution in Visual Studio 2012/2013 and the conversion should be smooth.

Open the InfoPath template inside your solution and copy it into a different location. Open it in design mode and open the code behind solution. When you try to compile it, you will end up with the below error.

“Unable to compile infopath solution using VS 2012 with below error. (Cannot add Microsoft.SharePoint.dll of SharePoint 2013 to an InfoPath 2010 C# code behind)”

"Warning 3 Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. NEW Security Request:”

The above error occurs because the InfoPath projects uses .net 2.0 as the target version. We will need to specift .net 4.5 as the target version.

You will need InfoPath 2013 installed in the server where you are building the visual studio solution to be able to compile the code successfully.

Install InfoPath 2013 in the server where you are building the visual studio solution.

After InfoPath 2013 is installed, VSTA will allow you to specify .net 4.5 as target version. The Previous error disappears. You will be welcomed with a new Error:

“An assembly with the same identity 'System.AddIn.Contract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' has already been imported.”

Try removing one of the duplicate references for the above assembly and the code should compile successfully.

Publish the InfoPath template to a network location and then copy the published template into the Visual Studio 2012/2013 solution.

Try creating a new InfoPath form instance.

The below error might show up:

"An error ocurred while trying to connect to a web service. An entry has been added to the Windows event log of the server. Log ID:5566"

Event log does not have any entries with Log ID:5566

When you attach the debugger to w3wp, the below exception might show up:

Exception: "The form cannot run the specified query."
Inner Exception Details: "Unknown Error"

The above exception is thrown when the code reaches FileQueryConnection.Execute(); if your contains the FileQueryConnection object.

It appears that InfoPath Form Services does not support claims based authentication.

This is a hard lesson. In SharePoint 2013, we can't switch to Classic/Windows Authentication easily in SharePoint 2013.

Recreate a new web application with windows authentication as authentication type using the PowerShell command below:

New-SPWebApplication -Name "{Name of Web App}" -ApplicationPool "{Application Pool Name}" -AuthenticationMethod "NTLM" -ApplicationPoolAccount "{DOMAIN\Account Name}" -Port {Port Number} -URL "{Web Application Url}"

Mount Content DB using the below command:

Mount-SPContentDatabase -Name {Content DB Name} -WebApplication {Web Application Url} -AssignNewDatabaseId

Re-upload all the data connections and activate the form template on the site collection in the newly created web application.

Try to create a new form or open an existing form and you should be ok now.

What is weird is that the InfoPath forms continue to work after migrate from classic-mode to claims-based authentication

Run the below PowerShell commands to change the authentication mode to claims based:

$WebAppName = "http://<yourWebAppUrl>"
$wa = get-SPWebApplication $WebAppName
$wa.UseClaimsAuthentication = $true
$wa.Update()

Hope that this helps someone.



2 comments:

  1. the link to Building the Visual Studio 2010 solution to deploy the InfoPath form by Dr. Nader doesnt open? Do you have another link to it?
    Or do you have anyother option to migrate the code ?

    ReplyDelete
  2. https://suehernandez.wordpress.com/2013/11/22/deploy-infopath-2010-with-code-as-solution-feature/

    ReplyDelete