How to REALLY deploy InfoPath 2010 forms with code behind as a SharePoint feature!

Introduction

It took me about 3 weeks in development hell till I figured it out. 3 posts in SharePoint official forums and tons of Googling and Binging; all weren’t enough. I almost thought it was not possible. Well, it’s possible alright! There is just one simple trick. All you have to do -in addition to the normal steps of deploying an InfoPath form without code in a feature- is to extract and publish the dll file in a specially formatted folder inside you feature’s folder.

I’ll try to keep this as simple as possible, and give you the conclusion I got to. There are a lot of intricacies that I can warn you about, but instead I’ll just give you the clean way I finally took, but first we need some background about the issue. If you’re already familiar with the matter, or just want the steps, skip the next section.

The Problem

SharePoint is heavily integrated with Office products like InfoPath. Unlike other Office products InfoPath documents -referred as forms- may or may not contain .NET code in them. Essentially a Form -the file with the xsn extension- is just a CAB package that contains several other files in them like the schema, fields, etc… When your form includes code the package also includes the compiled Dll file and here comes the problem. Deploying a form with no code behind is as simple as inheriting your feature receiver from XsnFeatureReceiver class. It handles just about anything, but when you form has code in it it must by administrator approved. This is done manually using the Central Admin, but if you’re deploying hundreds of forms to several sites? This is not practical. So you have to register the forms with Forms Services in your code, and since it’s the administrator who will activate the feature – it’s required to be activate as a farm solution not sandbox-, then implicitly you have the admin’s approval.

The Solution

  • Create your form in InfoPath, add the code you want normally.
    Sample InfoPath form
  • From the Ribbon choose the developer tab, open the code editor and add some code.
  • Save the code you’ve just added and close the code editor.
  • This step is important folks! Go to File => Publish => Publish the form to a network Location. I can’t stress enough that forgetting this step would ruin everything -even in publishing a form without code-. For the life of me I don’t know why.
  • More important; in the publishing wizard’s second step clear the text field that points to the public path of the file.Again don’t ask why. When a warning message box appears just press OK.
  • In the last step make sure that the security level is Domain, otherwise change that in the File => Form Options => Security and Trust
  • Create your SharePoint 2010 empty project in Visual Studio, and choose it to be deployed as farm solution.
  • Add a new feature to the solution with Site scope.
  • Add your mapped feature folder, then add a subfolder for your forms. Since your feature is not deployed yet you won’t have a Feature folder TemplatesFeatures SharePoint folder. A trick is to deploy your solution first and activate it then add the mapped folder. Your folder structure should look something like this
    Folder Structure
  • Finally, add a feature receiver and in the FeatureActivated event write the following code:
    N.B. In the following code most reference are available by default in the project so you just have to add the using statement, except for the FormsServiceclass you have to manually add reference to “C:Program FilesMicrosoft Office Servers14.0BinMicrosoft.Office.InfoPath.Server.dll”

The above code essentially does the following:

  1. Iterates on all the files in the InfoForms folder with the xsn extension
  2. Extract them into a uniquely identified temp folder
  3. Get the Form’s name from the Name attribute in the manifest
  4. If the form doesn’t exist in the target Forms Services, the form is uploaded and activated for the current site collection, Otherwise it’s just upgraded
  5. Finally it cleans up the temporary files and folders before closing
  6. Note that I gave a 30 seconds timeout on
  • Finally don’t forget to add clean up code that does the opposite by removing the forms from the site collection and Central Admin.

Now if you go to the Central admin => General Application Settings => Manage Form Templates you’ll find your form registered. Also if you go to http://YourSite/FormServerTemplates/Forms/All%20Forms.aspx You’ll find your form activated. Finally try opening it in the browser

Web InfoPath Form

Voila! I can’t even tell you how much pain I went through to get to this result. Now regardless whether you add new forms, delete forms or upgrade forms in the sub folder you specified, the event receiver will handle it for you. You can download a sample project and release package from here and here. I’ve added a sample submit list to illustrate how to submit this types of forms.

  • Pooja

    Hi Dr. Nader,

    I have used the method and steps you have explained in this article and have successfully uploaded my Infopath form with code as a feature to other domain. I was wondering if you could help me with publishing it as content type instead of as Site Collection Feature.
    Thanks in anticipation
    P

    • http://nader.elshehabi.com Dr. Nader

      Hello Pooja,

      Actually if the form has code behind it must be administrator approved, so it can not be published as a site content type since it will run with full trust security level. Refer to this article for more details http://office.microsoft.com/en-us/infopath-help/publish-a-form-template-to-a-server-running-infopath-forms-services-HP010100093.aspx#BM4

      • Pooja

        Thank you for the reply. I was wondering in that case will you be able to tell me how do I use the site Collection Feature. I need to use the Infopath form with code deployed as Site Collection Feature as a Form Template for one of the library.

        Thanks
        Pooja

        • http://nader.elshehabi.com Dr. Nader

          Actually, since you must publish the form to the site collection, I don’t think this feasible. My approach is to add a new data connection to the form that submits to a a list in my local development site, for example http://mylocalmachine/lists/targetlist/, in the submit options choose the you’ll submit using code, finally in the submit event add this code
          FileSubmitConnection fileSubmit = (FileSubmitConnection)this.DataConnections["My Submit Connection"];
          fileSubmit.FolderUrl = this.ServerInfo.SharePointSiteUrl.ToString() + "Lists/targetlist/";
          fileSubmit.Execute();

          This way you’ll submit to the specific list relative to your current server url.
          If you need to pass some values to the form there are several ways to do this. One simple way is the query string like illustrated here

  • Pooja

    Also, I wanted to know did you do any steps for the form to appear in FormServerTemplate because its not working like that in my case. I can’t see it at all in there.

    Regards,
    Pooja

    • Pooja

      An update: I guess Extrac32 is not working correctly without Visual Studio. I tried directly on CMD but it didnt extract files. Is there any other way you may be able to suggest? Or there is a way with your logic itself that can solve it. Please Help.

      • http://nader.elshehabi.com Dr. Nader

        I’ve edited the post and included a sample package at the bottom that I’ve tested personally. It was as simple as Add-SPSolution, Install-SPSolution, Enable-SPFeature. Download it and test it, however I faced some issues sometimes with the clean up code that I’ve put in the FeatureDeactivating. I’m too tired now to look into it.

        • http://www.newsdiablo3.org/ Diablo 3

          Greetings! Really useful assistance on this informative article! It really is the minor adjustments that make the largest adjustments. Many thanks a great deal for sharing!

      • Pooja

        Hello Dr. Nader,

        Thanks for the quick response. It seems the Manifest.XSF is getting extracted when performing FeatureDeactivating. But when Performing FeatureActivating it does not. It looks so confusing because the bit of extracting the Manifest.XSF file is exactly the same for the two.
        I am using Windows Server 2008 with Visual Studio 2010 and Infopath 2010 for developing the solutions. Yeah I checked your last post for the alternative methods. I don’t know how much will the size of the Package increase because of this. As, I will be required to do such many more of such applications and don’t want the server to get slow because of this added bit.
        Any thoughts? Please do let me know.

        • http://nader.elshehabi.com Dr. Nader

          Um!! One silly not that I noticed. On Windows Server 2008 you have to right click on SP PowerShell icon and explicitly choose to start it as administrator, otherwise the feature won’t be activated correctly like you say. Perhaps this is what’s it all about.

          • Pooja

            Oh I forgot to mention I fixed the extracting problem by setting the absolute path of cmd.exe i.e. “C:WindowsSystem32″. And obviously used Sharepoint Powershell as administrator.

    • Pooja

      Hello Dr. Nader,

      I really appreciate your help in the problem. Your solution is executing all fine till the point it need to extract CAB file and thats where its not working. Just trying to figure out if its even entering that Loop or not. but in the meanwhile, do you have a suggestion to implement it otherwise? I am really sorry to be bothering you so much.
      Regards
      Pooja

      • http://nader.elshehabi.com Dr. Nader

        Well, if for some reason your problem is all about extracting the xsn, you can treat it as a CAB file. Here is an excellent article about using Windows API directly to create class that can extract files from CAB archives -like in our case the xsn file-, however I don’t think it will be an easy task. Also here is a magnificent article in Code Project forums, where the author have implemented such API calls in a ready to use class. Using his dll however will mean that you’ll have to include his dll in your package and deploy it to GAC.
        The real question is why Extrac32 is not working with you? I tried the sample project on both windows 7 and windows server 2008 R2.

  • http://www.droiddog.com/forums/member.php?u=351794 Pasquale Aeling

    Hi there , I do think that is a fantastic weblog. I stumbled on it on Yahoo , i’ll arrive again when yet again. Income and flexibility may be the very best method to alter, may possibly you be abundant and support others.

  • Pooja

    Hello Dr. Nader,
    I tried Extrac32 directly on COmmand Prompt and it worked wonders. Now I am left wondering did you make some references etc to make it work from deploying via Sharepoint 2010 Management Shell? The project excutes fine till it needs to extract the files from XSN.

    Also, when I use ‘/C’ before Exctrac32 in _startInfo.Arguments, it directly executes the exception of ‘Extracting InfoPath forms timed out’, else, it waits till the time of 30 second elapses and then comes with error for manifest.xsf not found at the location. Any Ideas?

    • http://nader.elshehabi.com Dr. Nader

      Well, The is nothing special I did to make it work! Just download the wsp and install it using powershell!
      Try using the /C as you did and increase the Timeout from 30 seconds say to 3 minutes or so. Also what OS are you using is it a win7 dev machine or server 2008? Also check my last post, you can replace the use of extrac32 liek I did with the code from the articles I provided to give you a more consistent experience.

  • Pooja

    Hello Dr. Nader,
    Many thanks for the help. I eventually did manage to upload the form template with your help correctly. I accessed SPPowershell as an administrator and it worked.
    Many thanks once again for the amazing help you have extended in this issue.
    Regards
    Pooja

    • Pooja

      Oh I forgot to ask you one thing. The Sharepoint Project that we developed in this task contains a mapped folder to /Templates/Feature. But the server where I am deplying does not have anything like that already set. Do I need to create that folder first on that or directly I can move it using WSP and everything will be done automatically?

      Regards
      Pooja

      • http://nader.elshehabi.com Dr. Nader

        You’re welcome! I’m glad the problem is solved finally.
        Deploying the WSP using PowerShell or even in Central Admin will handle everything for you. Test it well, and if you still face any further issue I’ll gladly try my best to assist.

        • Poojagandhi

          Hello Dr. Nader,

          Hope you are doing great.

          I have been busy with moving the form over to other server and also in testing other bits and pieces related to it. I have one question for you with regards to the this article. When I use the method explained above all my fields just register as Read-only in the server. But I need to use them in my workflow and also update/set their value when required. Can you please explain on the process how I can acheive it?

          Regards
          Pooja

          • Anonymous

            As far as I know, publishing the form the way I describe in the post is identical to publishing it using Central Admin, only in an automated fashion. Try to publish your form as a test using the manual way in Central Admin. Does the same happen to your fields?

          • Poojagandhi

            Yes it still makes all my Content type fields as Read Only. Should I be including a seperate Element file for setting the fields as Read-write? Please help its urgent.

          • Anonymous

            Actually I haven’t work much with Workflows on SharePoint, so I won’t be much of a help. You can still post your question on MSDN forums, especially that your problem is not relative to the subject of the post. I wish I was of more help.

            Best wishes.

          • Poojagandhi

            Thank you so much for the response. I will definately post on MSDN.

            Regards
            Pooja

  • Pooja

    Hello Dr. Nader,
    I deleted the folder from Templates/Features and it still worked fine. Thanks for the solution and the dedicated help.
    Regards
    Pooja

  • http://exercise-equipment-reviews.org/ Elizabeth

    Very nice, i suggest Admin can set up a forum, so that we can talk and communicate.
    Nancy

  • Pooja

    Hello Dr. Nader,

    I have a few data connections which send and receive data from the sharepoint site and form. I need to move them as well to my new server. I was wondering if you could help me with that? Since the two server are disconnected so I cannot use the Universal Data Connection Library but need to modify it accordingly that they all point to new address.
    Can you help?

    Regards
    Pooja

    • http://nader.elshehabi.com Dr. Nader

      Have you checked my other article on Dynamically modifying udcx connection files?

      • Pooja

        Thanks for the response. I just checked it and it seems to be something similar to what I would be looking at. But I stumble upon to properly follow the method :
        1) what project type are you using?
        2) Are you performing all that in the same Project you created for the infopath form with code to be deployed as feature?
        3) how do I create a udcx file without mentioning the target server/site collection?

        Also to confirm i am using a SOAP connection in my form.

        Regards
        Pooja

        • http://nader.elshehabi.com Dr. Nader

          1) what project type are you using?
          2) Are you performing all that in the same Project you created for the infopath form with code to be deployed as feature?
          Yep! Empty SharePoint Feature, holding both. If you’ve download the package I included at the end of the post you’ll see the fully working project that submits to a Library on the server. This way you don’t even need a udcx. The udcx file I used in the attached example was to query not to submit.

          3) how do I create a udcx file without mentioning the target server/site collection?
          If you wish to use udcx files to submit using SOAP. Just specify your library as http://localhost/lists/mylib and modify the connection in the udcx using the code in the other post.

          • Pooja

            Well, Correct me if I am wrong: Don’t I need to convert all my data connections to UDCX (whether Recieveing data or submitting) if I am developing in a different domain and then packaging and moving to other? I have a few connections to receive and few to send. And both my servers Production and Developement. So If I need to create any data connection Library I can’t point to Production from Dev.
            Also, I am still not clear when you say ‘Deploy Data Connection Library in feature’ means? and is that appropriate in this context?
            Regards
            P

          • http://nader.elshehabi.com Dr. Nader

            Did you download the project attached Visual Studio Project? You can find it at the end of the post. It should answer all your questions.

  • Murthybsnvsn

    Hello Dr.Nader,

    Greetings,

    The above article is very good. Thanks for sharing this article.

    As i illustrated i followed the same process. I have the infopath 2010 xsn file which contains custom code behind it. It is a browser based form.

    I just have taken an empty project and placed my xsn in infoforms folder under my feature.

    I have n’t used sample submit list in my project.

    In my custom code of infopath xsn i have used Sharepoint object model code, like accessing some sharepoint libraries.
    Presently i am getting this exception:

    Type: SecurityException, Exception Message: Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ failed.

    Could you please help me in this regard, or do i went wrong any where.

    and also do we need to include the infopath project code in this solution. Please let me know.

    Thanks,
    Murthy

    • Anonymous

      Thanks Murthy for your comment. As for your question, please make sure that you’ve set the security level for the form as “Full Trust”. You can find this setting by clicking on the File tab in the ribbon => Advanced Form Options => Security and Trust.

      You must set the security level to full trust. Anything lower may cause the exception you’re facing.

      • Murthybsnvsn

        Hello Dr. Nader,

        Thanks for the reply.

        I have followed the above process illustrated by you and set Domain in infopath 2010 form.

        after that i changed and deployed once again, it is giving another error now as

        You do not have permissions to access a SharePoint list that contains data required for this form to function correctly.Please help in this regard.

        Thanks,
        Murthy.

        • Anonymous

          Hi,

          You should not set the security to domain, instead you should make it full trust. That’s a higher level of security trust. Try that and tell me what happens.

          • Murthybsnvsn

            Hello Dr.Nader,

            I set that to Full trust, and i got the exception as 

            You do not have permissions to access a SharePoint list that contains data required for this form to function correctly. 

            In my infopath form, i have drop down box values which are binding from the sharepoint list

            Please help me in this regard.

          • Anonymous

            It’s still a security issue. Make sure that you’ve rebuilt your solution, that the xsn you’ve included in your project is updated, and finally that the user accessing the form has permission to access the list.

      • Murthybsnvsn

        Hello Dr. Nader,

        Thanks for the reply.

        I have followed the above process illustrated by you and set Domain in infopath 2010 form.

        after that i changed and deployed once again, it is giving another error now as

        You do not have permissions to access a SharePoint list that contains data required for this form to function correctly.Please help in this regard.

        Thanks,
        Murthy.

        • NaderElshehabi

          Hi,

          You should not set the security to domain, instead you should make it full trust. That’s a higher level of security trust. Try that and tell me what happens.

          • Murthybsnvsn

            Hello Dr.Nader,

            I set that to Full trust, and i got the exception as 

            You do not have permissions to access a SharePoint list that contains data required for this form to function correctly. 

            In my infopath form, i have drop down box values which are binding from the sharepoint list

            Please help me in this regard.

          • NaderElshehabi

            It’s still a security issue. Make sure that you’ve rebuilt your solution, that the xsn you’ve included in your project is updated, and finally that the user accessing the form has permission to access the list.

  • http://www.facebook.com/aTIFSHAHZADSATTi Atif Shahzad Satti

    can you please help for mine problem???

    I have an infopath form(along with code behind) successfully published at central admin and so on.
    My case is that i have created a custom workflow and when a user clicks on the workflow task in a list, then this infopath opens in default WrkTaskIp.aspx page.But an error occurs like “An error occurred during the
    processing of /_layouts/WrkTaskIP.aspx. Only Content controls are allowed
    directly in a content page that contains Content controls”Can you please help me to get rid off this???

    • Anonymous

      I’m sorry, but I haven’t faced that error before.

  • http://www.facebook.com/aTIFSHAHZADSATTi Atif Shahzad Satti

    can you please help for mine problem???

    I have an infopath form(along with code behind) successfully published at central admin and so on.
    My case is that i have created a custom workflow and when a user clicks on the workflow task in a list, then this infopath opens in default WrkTaskIp.aspx page.But an error occurs like “An error occurred during the
    processing of /_layouts/WrkTaskIP.aspx. Only Content controls are allowed
    directly in a content page that contains Content controls”Can you please help me to get rid off this???

    • NaderElshehabi

      I’m sorry, but I haven’t faced that error before.

  • Nagarajsd

    Hi I have followed this procedure because in my infopath form having managed code which involves lots of code but when i deploy to testing environment the infopath form will not show in the form server template but when i check the feature folder in 14 folder the feature is showing and even in my forms folder also with error log but in the site collection the template not showing and in site collection feature also the infopath form not showing is there any thing need to do modification in the coding

    • Anonymous

      Your message is quiet unclear. Did you follow the steps in the article exactly? If you’re catching the exceptions and writing an error log, is there anything in your logs? Does the temp folder get deleted? When you go to Central admin => General Application Settings => Manage Form Templates do you see your form?

  • Nagarajsd

    Hi I have followed this procedure because in my infopath form having managed code which involves lots of code but when i deploy to testing environment the infopath form will not show in the form server template but when i check the feature folder in 14 folder the feature is showing and even in my forms folder also with error log but in the site collection the template not showing and in site collection feature also the infopath form not showing is there any thing need to do modification in the coding

    • NaderElshehabi

      Your message is quiet unclear. Did you follow the steps in the article exactly? If you’re catching the exceptions and writing an error log, is there anything in your logs? Does the temp folder get deleted? When you go to Central admin => General Application Settings => Manage Form Templates do you see your form?

  • Nagarajsd

    many thanks for your reply 

    actually when we do these step from VS2010 it’s working fine but when we take solution(.wsp)package and activate to other server for new site collection also the feature get activated and even the feature showing in the 14 hive folder but in site collection the form server template gallery the infopath form it’s not showing but when i check the error.txt from 14 hive folder for the feature folder it says access denied
    Please let me know 

    • Anonymous

      There you have it! The error is self explained. The user account you use to deploy the package don’t have write access to the features folder. When you develop for SharePoint usually you run VS as administrator; Did you run the command prompt / PowerShell as administrator?

  • Nagarajsd

    many thanks for your reply 

    actually when we do these step from VS2010 it’s working fine but when we take solution(.wsp)package and activate to other server for new site collection also the feature get activated and even the feature showing in the 14 hive folder but in site collection the form server template gallery the infopath form it’s not showing but when i check the error.txt from 14 hive folder for the feature folder it says access denied
    Please let me know 

    • NaderElshehabi

      There you have it! The error is self explained. The user account you use to deploy the package don’t have write access to the features folder. When you develop for SharePoint usually you run VS as administrator; Did you run the command prompt / PowerShell as administrator?

  • Anil Rituwal

    i a getting access denied error on feature activation. enable to access the form from location
    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TemplateFeaturesInfopathFormDeployer_Feature1/InfoForms/MyForm.xsn on this codealFormsService.FormTemplates.UploadFormTemplate(_filename);

  • Anil Rituwal

    i a getting access denied error on feature activation. enable to access the form from location
    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TemplateFeaturesInfopathFormDeployer_Feature1/InfoForms/MyForm.xsn on this codealFormsService.FormTemplates.UploadFormTemplate(_filename);

  • Linash2009

    alFormsService.FormTemplates.UploadFormTemplate(_filename);

    getting exception here when loading the form to form library

  • Linash2009

    alFormsService.FormTemplates.UploadFormTemplate(_filename);

    getting exception here when loading the form to form library

  • Denkyira

    I have followed the well documented step by steps but I can’t see my form at central admin under Templates. I can see the feature, but not the form under Central admin => General Application Settings => Manage Form Templates

    • NaderElshehabi

      Go to the feature’s folder. Do you see the temp folder and / or an error log? If you can see the error log file, what errors are in it?

  • Denkyira

    I have followed the well documented step by steps but I can’t see my form at central admin under Templates. I can see the feature, but not the form under Central admin => General Application Settings => Manage Form Templates

    • NaderElshehabi

      Go to the feature’s folder. Do you see the temp folder and / or an error log? If you can see the error log file, what errors are in it?

  • Andrew Carter

    Love the post .. this is just what I need on a project I am working on .. I took your code and implemented this in my feature activated event .. modified with some logging – packaged my solution and added/installed via PowerShell as Run As Admin; feature deployed and I saw the wsp in the farm solutions as deployed .. great ..  there was an error in the error.log; and I am not too sure if this was before or after I activated the solution at site collection level .. Access Denied .. Much Confused .. my account is local admin  Site Collection Admin and Farm Admin .. I then downloaded your source to compare and test .. packaged and deployed in same fashion; I noted that before the feature is activated at a site collection level your “MyForm” is also deployed as a WSP file as a farm solution, I also note that the feature deployed to the site collection is only the MyForm feature and I can not see your actual feature with list definition / instance deployed .. My question then is do the included xsn files get deployed automatically when you install the SP-Solution or when activated at the collection level; and how if you did, did you associate your xsn with the list definition ??

    Again great work, can not believe how PAINFULL this has been made  for something within the application seems soo simple ..

    • NaderElshehabi

      Thank you for your comment Andrew. Yes things can and usually do get nasty with SharePoint especially when it comes to development, not just customization.

      Readers, have been getting several access denied exceptions, and unfortunately those has to be investigated case by case. You can be the admin of everything in your domain, and still get an exception :) Anyway to your questions:

      The forms are deployed when you activated the feature, not install it and intuitively removed from the Form Library when you deactivate it. It’s only one feature as you can see so the forms don’t have their own feature as would be expected in ordinary deployment, rather they’re deployed manually by code in the feature activated even handler.

      Associating your forms with a library / list is discussed in a separate article. There are several methods, and I choose a simple one. You can find the article here .

    • Andrew Carter

      Looking into this Access Denied issue more closely I have noticed that InfoPath checks whether or not the user is a Farm admin, which I am.

      However the code used in the InfoPath DLL will only work if run under the context of the Central Admin website apparently, otherwise it has to be the overloaded method CurrentUserIsAdministrator(true) … I am still at a lose however how when deploying locally from VS2010 the feature is activated correctly without error … I am presuming that this is because the deployment commands are run as a x64 console application when using MSBuild ..

      • Andrew Carter

        Finally got this working .. The feature has to be activated at Central Admin (property on feature set to True) .. this then passes the CurrentUserIsAdministrator check (if run under suitable account) and installs the form correctly. However, this does mean that all InfoPath forms will have to be packaged in a Central Admin Only feature with no other web features included as these are not presented to the other site collections, only the forms are propergated down when activated. Phew ..

        • http://nader.elshehabi.com Dr. Nader

          Thanks Andrew for your valuable contribution to the discussion.

          I wonder though about the trouble you faced, because I used to deploy and activate the feature through PowerShell as well as Central Admin. As long as the user account has the necessary privileges it shouldn’t matter.

          As for deploying Infopath forms alone in a feature; I believe that you can pack anything you want with the forms in the same feature as long as that feature will be deployed and activated by farm administrator.

          I’m glad though that you worked it out.

  • Andrew Carter

    Love the post .. this is just what I need on a project I am working on .. I took your code and implemented this in my feature activated event .. modified with some logging – packaged my solution and added/installed via PowerShell as Run As Admin; feature deployed and I saw the wsp in the farm solutions as deployed .. great ..  there was an error in the error.log; and I am not too sure if this was before or after I activated the solution at site collection level .. Access Denied .. Much Confused .. my account is local admin  Site Collection Admin and Farm Admin .. I then downloaded your source to compare and test .. packaged and deployed in same fashion; I noted that before the feature is activated at a site collection level your “MyForm” is also deployed as a WSP file as a farm solution, I also note that the feature deployed to the site collection is only the MyForm feature and I can not see your actual feature with list definition / instance deployed .. My question then is do the included xsn files get deployed automatically when you install the SP-Solution or when activated at the collection level; and how if you did, did you associate your xsn with the list definition ??

    Again great work, can not believe how PAINFULL this has been made  for something within the application seems soo simple ..

    • NaderElshehabi

      Thank you for your comment Andrew. Yes things can and usually do get nasty with SharePoint especially when it comes to development, not just customization.

      Readers, have been getting several access denied exceptions, and unfortunately those has to be investigated case by case. You can be the admin of everything in your domain, and still get an exception :) Anyway to your questions:

      The forms are deployed when you activated the feature, not install it and intuitively removed from the Form Library when you deactivate it. It’s only one feature as you can see so the forms don’t have their own feature as would be expected in ordinary deployment, rather they’re deployed manually by code in the feature activated even handler.

      Associating your forms with a library / list is discussed in a separate article. There are several methods, and I choose a simple one. You can find the article here : http://nader.elshehabi.com/2011/09/dynamically-modifying-udcx-connection-files

    • Andrew Carter

      Looking into this Access Denied issue more closely I have noticed that InfoPath checks whether or not the user is a Farm admin, which I am.

      However the code used in the InfoPath DLL will only work if run under the context of the Central Admin website apparently, otherwise it has to be the overloaded method CurrentUserIsAdministrator(true) … I am still at a lose however how when deploying locally from VS2010 the feature is activated correctly without error … I am presuming that this is because the deployment commands are run as a x64 console application when using MSBuild ..

      • Andrew Carter

        Finally got this working .. The feature has to be activated at Central Admin (property on feature set to True) .. this then passes the CurrentUserIsAdministrator check (if run under suitable account) and installs the form correctly. However, this does mean that all InfoPath forms will have to be packaged in a Central Admin Only feature with no other web features included as these are not presented to the other site collections, only the forms are propergated down when activated. Phew ..

  • Pingback: How to deploy InfoPath forms with code as part of a feature « Buzz Blog

  • Pingback: How to deploy InfoPath forms with code as part of a feature « SharePoint (and Project Server) Shenanigans Test

  • http://profiles.google.com/talktopete Pete Weissbrod
  • Hatemmira90

    It doesn’t work. there is an error in deployment. It can’t find the manifest file although the file exists.
    The error msg: “Error occurred in deployment step ‘Activate Features’: Could not find file ‘C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TemplateFeaturesSharePointProject13_InfoPathPublishertempa38292b4-c8fa-4589-a25a-c9dc4aa95827manifest.xsf’.”

  • Yasotha

    Hi,
    If we publish the Administrator Approved forms, the user of the forms (real end users who will fill up the forms and submit) needs what kind of permissions in SharePoint library?

  • May

    Thank you very for your post. This is wonderful post.

    I already download you wsp file. and deploy it to central admin.

    Now, I want to delete My Form.xsn from Managege Form Templates.

    After deployed wsp file, I am going to site collection feature on central admins, then deactive FormsDeplymentFeature feature. But, I still see My Form.xsn on Manage Form Template.

    Can you show me that step by step to delete My Form.xsn from Manage Form Templates on Central Admin.

    Thank you so much

  • Jordan

    Thanks a lot for your post. It helps me a lot.

    But what bothers me is the “Publish the form to a network Location” procedure. This means that we have to do something manually for each form file. It is unacceptable for automation. I can not tell the difference between publishint it to the sharepoint server directively throught the publish guide and the
    procedure you provide. Like what you said, if we got thousands of forms to deploy, your procedure won’t help that much.

    Now I am digging into this problem and trying to figure it out.
    If you guys have any idea about it, do not hesitate to inform me please.
    I am available via taojinqiu1990@gmail.com

    Best regards,
    Jordan

  • Idam Satriya

    i’m still confuse with this part : “A trick is to deploy your solution first and activate it then add the mapped folder”. can you give some detail explanation about that?Thanks.