locked
infopath with code, publish to sharepoint RRS feed

  • Question

  • I am trying to make a sharepoint doc library based on an infopath form that I made.  If I do it without a code behind, I can publish and create a new library.

    When I try to publish with a codebehind, I can't figure out how to make a library.  I can publish to another library, but it doesn't become the content type, it is just basically an uploaded document.  If I go to the sharepoint designer, I can see it in mylibraryname folder.  When I create a new library, and try to go to advanced settings->and try to type in the template url (mylibraryname/form.xsn), it says I can't do that unless the form I am pointing to is in the forms directory (meaning mylibraryname/forms/form.xsn).  It also says that it can't be moved.  I even tried to move it to the forms directory in the sharepoint designer.

    So basically, how do I create (or publish) a from to a sharepoint library with code behind? When I am done, if you go to this library and click new, my form should display.
    nonam
    Wednesday, November 12, 2008 8:29 PM

Answers

  •  As I mentioned previously, the code is compiled into a DLL (dynamic link library) and it is packaged inside the template file (XSN) so when you publish the form, the published template already has the code compiled into it. Wherever you copy the published form, the code goes with it (in the form of dll) but if you want to edit the form, then you need  your code and that has to copied manually if you move your form to another location.
    SSA - http://sharepointblogs.com/ssa
    • Marked as answer by jmillman Friday, November 21, 2008 4:18 PM
    Friday, November 14, 2008 10:39 PM

All replies

  • Hi

    InfoPath form with code cannot be published directly to the SharePoint library. You have to publish it as an administrator approved form on your local drive and then upload it to the server. You must assign full trust to the form. Following article shows all the steps to publish a form with code:

    http://geekswithblogs.net/jgmeyer/archive/2006/06/26/83087.aspx




    SSA - http://sharepointblogs.com/ssa
    Wednesday, November 12, 2008 11:04 PM
  • Thanks, but I am working on a dev machine and need to get my form on a server. 

    #5. You must choose a location to save the template file, which will be uploaded to the SharePoint site by the site administrator.

    This doesn't apply.  Since I am working on a dev machine, central admin is on the server, so I need to save it there.  I need to somehow get the form to my server first.  I tried cutting and pasting, which I don't think you can do with infopath, I got an error when I tried opening the form.  I tried making an installer and putting it on the server, but the codebehind didn't come along.

    Any ideas?
    nonam
    Friday, November 14, 2008 4:33 PM
  • Hi

    This applies in your case. Even if you are working on a DEV machine, the publishing process is same. Publish the form to your local hard disk. InfoPath will create a file with .xsn extension. You dont need a separate code behind file. Everything is included in this template xsn file. If you have access to the central admin, upload it yourself otherwise send this file to your admin and he will upload it to the server. This xsn, after uploading, has to be activated and then the content type is added to the library where this form is to be accessed.
    SSA - http://sharepointblogs.com/ssa
    Friday, November 14, 2008 7:29 PM
  • Thanks for the reply. 

    Please clarify this:

    If I create an infopath form with a code behind then make a copy of the infopath form using copy/paste, then try to open the new form, I get an error and don't see the code behind.

    If instead of copying and pasting, I publish to my local computer, I can then copy and paste the published file anywhere and it can be opened with the c# code?  So basically my problem was that I did not publish to my own computer before copying?

    Thanks again
    nonam
    Friday, November 14, 2008 7:56 PM
  • I just opened my form in design mode, published to a new folder on my computer then tried to open the newly published form.  It opened well, but I don't have my codebehind anymore.  How do you create copies of infopath forms?  I really don't understand why such a simple task is so difficult (or at least so hard to find a solution for).


    nonam
    Friday, November 14, 2008 8:00 PM
  • When you publish the form, all files are packaged in the .XSN (template) and the code is also packaged in the XSN in the form of a DLL. If you want to copy the code behind, you will have to do it manually. There are different methods to create infoPath forms. If you create a form using Visual studio. Visual studio will create a directory and put your form and all code behind files in the same folder and it will be easier for you to copy the files to another location but if you create a form using the InfoPath designer then the code behind files are stored in a different location and you have to copy the files from that folder yourself. Simply copying the form will not move the code behind files to the new location. Go to Tools > Form Options in your infopath designer and select Programming from the catgory box. In the programming language section, there is a field called "Project location for Visual Basic and C# code". This is the location where your code behind is stored. It will be stored in a folder called template (it will be template1, template2 or something similar depending on how many template folders are already there).

    Hope this helps!
    SSA - http://sharepointblogs.com/ssa
    Friday, November 14, 2008 8:23 PM
  • Thanks, I think I got it working.  I found my code.  I published to another folder, then copied my codebehind project folder to that folder, opened the new form, and pointed the code to the new code copy.

    Isn't this pretty terrible?  Is there a better way to do this?  Why does the code not get moved during a publish?  When I publish to a network location and open it in sharepoint, where does the code go?  I didn't move my project files, but the code seems to work.

    Thanks again


    nonam
    Friday, November 14, 2008 8:41 PM
  •  As I mentioned previously, the code is compiled into a DLL (dynamic link library) and it is packaged inside the template file (XSN) so when you publish the form, the published template already has the code compiled into it. Wherever you copy the published form, the code goes with it (in the form of dll) but if you want to edit the form, then you need  your code and that has to copied manually if you move your form to another location.
    SSA - http://sharepointblogs.com/ssa
    • Marked as answer by jmillman Friday, November 21, 2008 4:18 PM
    Friday, November 14, 2008 10:39 PM