Skip to main content

Share Point

Go Search
Home
Announcements
Who Are We
Blogs
  
Share Point > Articles > Developing InfoPath Forms For Anonymous Access  

Web Part Page Title Bar image
Developing InfoPath Forms for Anonymous Access

Bu makalenin Türkçe versiyonu için tıklayınız...

There has always been a problem to add items to a list anonymously on WSS 3.0 and MOSS 2007. Since InfoPath forms are stored on form libraries, form libraries are special document libraries and document libraries are specialized lists, I don't hesitate to say that enabling users to fill out an InfoPath form anonymously is a problem.

It is possible to give view access to anonymous users for a document library, but when it comes to add access; it is not possible. So, an anonymous user can view and fill out a form served on InfoPath Form services , but when the user gets an error when "Save" link is clicked.

There is not a trick to solve this issue; we have to change out perspective. A filled out form can be submitted. Our approach will be developing a web service that can save a xml string to a form library as a document and configuring the submit option in order the form to pass the entered information to the developed web service.

First of all, let's write a web method to our web service like below:

[WebMethod]
public void SubmitToFormLibrary(string siteName, string webName, string formLibraryName, string formName, string formXml)
{
       formName = formName.TrimEnd('.');
       SPSite site = new SPSite(siteName + "/");
       SPWeb web = site.OpenWeb(webName);
       SPFolder folder = web.GetFolder(formLibraryName);
       foreach (SPFile file in folder.Files)
       {
              if (file.Name.Replace(".xml", "") == formName)
                     throw new Exception("File name exists.");
       }
       folder.Files.Add(formName + ".xml", UnicodeEncoding.UTF8.GetBytes(formXml));
}

There are several string typed parameters. What these are for is explained below:
  • siteName: The address of the site collection which the web service will submit the entered information
  • webName: The name of the site which the web service will submit the entered information
  • formLibraryName: The name of the form library which the web service will submit the entered information
  • formXml: The entered information

We can host our web service anywhere on IIS. The most important thing here is not to forget setting the windows identity of the application. Our web service will be using windows authentication to reach the form library on MOSS 2007. At this point we have to:

  1. Aggree on a user account for submitting the entered data, and giving it the add access on the form library.
  2. set the indentity of the web service as the agreed user account.

To accomplish the second task, we have to modify the web.config of the web service application as below.
<authorization>
    <allow users="*" />
</authorization>
<identity impersonate="true" userName="OFFICESERVERS\administrator" password="P@ssw0rd" />

With this configuration when a user submits the form to the web service, the web service application will connect to MOSS 2007 with OFFICESERVERS\administrator account and save the data as a file.

We have to be very careful about the file name of the xml data we'll be saving. Since, every submitted form has to be saved with a unique name, you can implement a counter in the web service or, if you're getting a unique data  among users from the form, you can use this data as the file name. We'll be using the tax number of the user since we want the user to fill in the form.

On the InfoPath form part, we have to start with creating the form. I have created the form below just by dragging and droping.


I have changed the names of the fields to meaningful names. After that, I have created 3 more fields to hold the values for siteName, webName, formLibraryName parameters of the web service. I have configured the fields as below.


With this configuration, we have set the save location of the entered data as the form library located at http://portal.officeservers.com/FL url.

It's now time for configuring the submit options of the form. On InfoPath we click on Tools -> Submit Options section. On the menu we face, we click on the "Allow users to submit this form" check box. "While Send this form to a single destination" radio button is selected, we select the "Web Service" option on the drop down list below. On the same menu, we click on the "Add" button. A wizard starts, and on the first step of the wizard we enter the url of the web service we developed. On the second step we select the web method will be used for submitting and we face with the menu below as the third step.


On this menu, we match the parameters of the web service with the fields on the form. When we double click on the options starting with "tns" text, we can select the fields on our form.  For "tns:siteName" we select "siteName", for "tns:webName" we select "webName", for "tns:formLibraryName" we select "formLibraryName" fields as values of the parameters. When it comed to the "tns:formName" parameter, I will be using the taxno field which is unique among users. For the "tns:formXml" parameters, we change the option on the menu from the default selected "Field of group" to "Entire form. After the change of the selection, "Submit data as string" check box is enabled and we click that check box. On the last step of the wizard, we give a name to our connection and it's done.

The operations after this step is the same as publishing a InfoPath form to InfoPath Form Services. Don't forget to save the web service connection to a data connection library before publishing the form.

PS: Once, I had to change the <allow users="*" /> tag to <allow users="?" /> on the web service's web.config file.

Author: Nezih Tınas ( MVP )

E-Mail:nezih.tinas@paylasimnoktasi.com

Article Date: 28.08.2007