Infopath form with managed code


Badge +8

Is it possible to include .Net code in Infopath browser-enabled forms if you want to use them in Blackpearl?


It's quite easy to develop a workflow based on a codeless Infopath form, but I still cannot figure out how to deploy a form with embedded code, as it has to be approve first by an Sharepoint administrator.


Any idea?


22 replies

Badge +9

As far as I recall.  Having code in the form makes it browser incompatible. So far we haven't found any way around this.  This has nothing to do with K2 [blackpearl] but rather more of the limitations of browser enabled InfoPath forms with Forms Server.


If anybody has found any new update which makes this possible, I would really like to hear about it.

Badge +1

Hi,


I don't believe the above is true regarding code-behind and web campatiablilty of InfoPath Forms. The only issue is that administrators have to upload and activate the form through Central Admin on the SharePoint site for the forms to work.


To deploy a form to SharePoint with code behind publish the form to a common network location(the wizard will take care of this - first option on first screen). Have the administrator upload the form using Central Admin and then activate it for your site collection. This form will then appear a content type which you can use as you wish in any document or forms library.


 

Badge +8

That is correct, forms with .Net enabled code can be deployed as web enabled forms but they need to be deployed through central administration.


http://spsfactory.blogspot.com/2007/01/walkthrough-publishing-administrator.html


http://technet2.microsoft.com/Office/en-us/library/8285b82e-19db-4408-859f-1430830fe0fb1033.mspx?mfr=true


BlackPearl now publishes the InfoPath form but this does not seem to be accomodated.  Maybe there could be an option added to the wizard which would deploy the InfoPath form to central administration and performing the other actions needed.

Badge +9

Excellent pointer.  From this information, it allowed me to find this excellent article - Creating InfoPath Form Templates That Work With Forms Services (http://msdn2.microsoft.com/en-us/library/aa945450(VS.80).aspx) which contains the following.



Note:

After publishing a browser-enabled form template that contains managed code to Microsoft Office Forms Server 2007, to Office SharePoint Server 2007 with InfoPath Forms Services, or to a shared location, the form template must be uploaded and approved by a server administrator before it will be allowed to run.


These other links were also pretty useful in understanding the limitations of Web Enabled InfoPath forms.


Badge +8

Yep 🙂


 I have developed many forms with embedded .net code, and they perfectly work in a Forms Services environment (the object model is limited compared to the rich client's, but it's fine).


The problem now is about using them with Blackpearl. When I first heard about the release of the MOSS components for K2.net 2003 in Feb. 2007, I felt like I could do everything with my forms, but unfortunately, forms with embedded code were not supported. Then I put my hope in Blackpearl and... second disappointment: nothing is made to include forms that require administrator approval. Or at least nothing easily visible.


 Are there already K2 Blackpearl specialists who could just say if it's possible? Even if they don't know yet how to do 🙂

Badge +8

...


 After hours (even days!) of suffering and pain, I have just found how to use web-enabled Infopath forms with embedded code with K2 Blackpearl workflow.


 I may write a real tutorial one day but for the moment, here are the required steps (maybe there's an easier way to achieve the goal, but I havn't found it):



  • Create a Infopath form aimed to be open in a browser
  • Design your form (add the groups and fields, the data connections, etc.) BUT don't add .Net code now (it may work but that's not how I did it)
  • Create your K2 project in VS 2005
  • Design your workflow just like in the Infopath tutorial provided with the Blackpearl documentation until step 5; this step of the tutorial is the one where you must re-design the form to adapt it. Add your .net code now. When you're done, do not finish the Infopath Integration Wizard.
  • In the Infopath Integration Wizard, edit the properties associated to your forms (ie "publish to") and set the form library where you'd like to see your form published. Select "content type" instead of "form library template", and do not forget to set the opening program as "web browser".
  • Finish the wizard, and deploy your project
  • Now go to the form library, the "settings", and delete all the content types set for this library.
  • On the same site, click on "View all site content", you should see a "K2 Blackpearl Form Templates" or something like this. Open the lib. It contains the form you've just deployed. Right-click it, and copy shortcut to this XSN file.
  • Go to your MOSS Central Administration, "Application Management" --> "Manage Form Templates", and click on "Upload a form template".
  • Click the "Browse" button, paste the shortcut, and click "Ok". This file browser is not made to browse URLs, but it works.
  • Confirm the upload of this form template (you can verify it if you want, but it's quite useless)
  • Activate it to your site collection
  • Go back to your site, and to your form library
  • Click "settings", and add an existing content type. In the list, you should find the name of your form (eg: "my form"), plus the name of your form with a suffix which should be "1" (eg: "my form1"). Select this one (the first one is the content type automatically deployed by Blackpearl, do not select it as it's not admin-approved)
  • Now go back to the form lib, create a new instance of the form, and.......... it works!!!

It's friday evening, I've just written this after getting successful, so please don't be rude if you spot errors or approximations in this quick and dirty tutorial 🙂


Nevertheless, if you're in trouble with a particular step, do not hesitate to ask for details.


 

Badge +8
Really cool that you went through this.  Everyone is going to start hitting this.  I hope this is resolved in a SP as part of the deployment process.  Will be kinda of hard to resolve because developers may not admin rights to central administration.
Badge +3

Is all this really necessary? Did the hotfix change any of this. 


Using code behind in infopath seems so natural, is it really cross the grain with K2 BP functionality.


Have you tried updating the form?

Badge +8
As far as I know, the different hotfixes didn't solve this problem (it's not a bug, it's a missing feature). This is expected to come with SP1 (H1 2008).
Badge +8
That will be awesome if they do; my only concern is that the person doing the deployment must have an account that can access central administration.  May not always be the case.
Badge

Just to make a little phrase correction "This file browser is not made to browse URLs , but it works."


The realy things happen is, when you paste URL location of the template you actually browse to temporary location of the IE. So, in fact you upload the file from local directory.


 Thanks,


Riwut

Badge +9
Does anyone know if this has been addresses with SP1?  I'm just getting started with Infopath integration, and I'd like to know its limitations (or extra hoops I'll have to jump through).  Thanks!
Badge +8
No, nothing new on that side. It's still very annoying. I'm currently struggling to put everything in web services methods or SmartObjects... But it's definitely not as powerful as adding code directly in the form template.
Badge +3
Nicolas, are you shying away from using managed code in your IP forms because of the hassle?
Badge +8

Yes I am... It's so complicated that doing it once or twice is possible, but after the 3rd revision of your process and/or from, you get bored.


The workaround is usable if you have to design a small number of processes / forms, but if you develop at an industrial level, forget about it: it's clearly not maintainable.

Badge +8

Ok - well I had meant to get back to this and it has been some time now.  I spent my Saturday playing around with this and I have posted this to help.  I refined some of the steps that we laid out earlier which have made redeployment of the InfoPath form with changes significantly easier.  Using content types was the key.


Deploying K2 InfoPath Web Enabled Forms with Managed Code - http://k2distillery.blogspot.com/2008/01/deploying-k2-infopath-web-enabled-forms.html


Hope this helps - comments are welcome - I tested it a few times.


Jason

Badge +8

Thanks Jason! Really Useful.


However, I disagree when you say K2 developpers may never be able to find a way to automate this process ;-)

Badge +3

Thanks everybody for the detailed steps...however I can't seem to get this work.


 Whenever I have code in an InfoPath form, if I go to the "K2 BlackPearl InfoPath Form Templates" and choose to 'Edit in Browser', immediately I get the following page: The form has been closed.


It works if I click the "K2 BlackPearl InfoPath Form Templates" link and choose "Edit in Microsoft Office InfoPath".  I have followed the steps detailed in previous posts here, as well as the steps on Jason's blog, but the form always closes immediately.

 

Any ideas?  I'm willing to try anything at this point...InfoPath is severely limited without the code option.
Badge +8
Are you at the point where you need to retrieve the deployed InfoPath form so you can redeploy it through MOSS Central Administration?
Badge +3

I walked through all of your steps, so I activated the template to my site collection.  Is that what you mean?


 I've never used code in InfoPath, so I'm thinking there might be some security configuration somewhere to allow the InfoPath code to run:(

Badge +3

Turns out the form that works with script is found in the "Form Templates" folder on SharePoint and I was trying the template in the "K2 BlackPearl InfoPath Templates" folder.


 So basically I'm an idiot and I was just looking in the wrong folder.  Thanks for your help.

Badge +6
Just to follow this thread: have a look at this post in the "HOW TO K2": Using “code behind” with InfoPath forms, SharePoint and K2

Reply