4 min read

 

Given the inbuilt SharePoint restrictions on submitting an InfoPath form with anonymous access, this document outlines the steps to change the InfoPath form and publish it to a SharePoint environment, to allow an anonymous access.

Steps:

Make change to the InfoPath form

 

Also in this Youtube video

http://www.youtube.com/watch?v=ZMvYQ9P1loU

 

  1. Change the submission code in InfoPath to :
    1. Go to Data tab -> Data Connections

       

       

    2. Remove the existing Main Submit connection. Then click on Add button.
    3. On Data connection wizard -> Select Submit Data option and click on next button

    4. Select “To a document library on SharePoint site” option and click on next button

       

    5. Specify URL of Document Library and click on “fx” button and paste below formula and click on verify formula button and select “Allow overwrite if file exists” option and click on next button.

    concat(“Form – “, my:UserLastName, ” “, my:UserFirstName, ” – “, xdDate:Now())

    1. Give the name of data connection and click on finish button. Note: Verify that “Set as default submit connection option is selected”.

       

    2. On Data Connections dialog, select the submit data connection that you created in above steps and click on “Convert to Connection File” button.

       

    3. On Convert Data Connection dialog specify valid URL of Data Connections library (e.g. http://<server:port>/DataConnections/ContactUsDataFile.udcx) and select “Centrally managed connection library” and click on OK button.

      If the data connection library does not exist in the SharePoint site in which you are publishing the InfoPath Form, then create a Data Connection library in that SharePoint Site. Refer section “To create a SharePoint Data Connection Library” in this link http://msdn.microsoft.com/en-us/library/ms772101%28v=office.14%29.aspx for steps to create data connection library.

       

      Note: We have to create data connection library for temporarily saving the Data Connection file. After the data connection is converted and user downloads that data connection file (.udcx file) then there is no need of this library. As we will be storing the data connections in Central Administration.

       

       

       

    4. Now go to File -> Form Options

       

       

       

    5. On Form Options dialog -> on Programming category :
      1. Click on “Remove Code” button if it is enabled.
      2. Select “C#” as Form template code language
      3. Specify appropriate location for the code
      4. Click on OK button

    6. Right click on Submit button and click on “Button Properties”

       

    7. Verify whether “Rules and Custom Code” option if selected for the action, if not please select that option and click on Edit Form Code button.

       

    8. Once visual studio opens, add reference of Microsoft.SharePoint.dll to the visual studio project
      1. Right click on “References” option in Project explorer and click on “Add Reference”.

      2. On Add Reference dialog, click on browse tab and enter following location in filename textbox and click on OK button.

        C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\ISAPI\ Microsoft.SharePoint.dll

         

    9. Now add following code to using section at the top of “formcode.cs” file

      using Microsoft.SharePoint;

    10. Now paste the following code under “SubmitButton_Clicked” method

      SPSecurity.RunWithElevatedPrivileges(delegate()

    {


    this.Submit();

    });

            

    1. Now save the file and build the project and close the project. Note: The project should build successfully. To build the project, go to Build menu in visual studio and build the project.

     

    NOTE: User should go to Build menu in visual studio to build the project

    1. Now you can publish the form.

Publish the form to SharePoint Central Admin

 

Publish InfoPath Form to SharePoint 2010

Follow the instructions in below link to publish the InfoPath form from Central Administration:

http://msdn.microsoft.com/en-us/library/ms772405%28v=office.14%29.aspx

Once the form is uploaded and activated to relevant site collection, then you can add Content Type

Upload Data Connection to SharePoint Central Admin

 

Also in this Youtube video

http://www.youtube.com/watch?v=8dXtSK5wVDY

Note: this is for 2007, but the steps are the same for 2010

 

  1. Download the data connection (ContactUsDataFile.udcx) file from the SharePoint site where you had saved it in above step (h).
  2. Open the ContactUsDataFile.udcx file in notepad and specify the URL of your Forms Library inside the <udc:FolderName AllowOverwrite=”1″> tag.

    e.g. <udc:FolderName AllowOverwrite=”1″><FULL URL to forms library in SharePoint site></udc:FolderName>

     

     

  3. Now to upload the data connection file to Central Administration, follow the instructions under “To upload a data connection file by using Central Administration” header on this link: http://technet.microsoft.com/en-us/library/ff621104%28v=office.14%29.aspx
  4. Apply a Content Type to the form to the library.