In this article I will explain how can we create and publish browser enabled
InfoPath form in SharePoint site.
Steps Involve
1. Step 1: Design info path form
2. Step 2: Creating Installable InfoPath form Template
3. Step 3: Deploying form in SharePoint
Step 1: (Design Info Path Form)
To design InfoPath form please refer to my previous article "Creating
browser enabled InfoPath forms for SharePoint library"
After designing form Right click on button control (which you have added in your
form) and select button properties.
Select Submit from the "Action" dropdown and Change the label of button and
click on "Submit Option" button. Click on "Submit Option" button.
From submit options popup, Click on "Allow users to submit this form "check box,
select "Perform custom action using Code" and click on "Edit Code…" button.
Now Visual Studio project will be open where you can write your code to submit
data into SharePoint library.
Steps to select your programming language and project location(Before clicking
on Edit Code
button)
- Go to "Form Options" from the Tools menu.
- Click on "Programming" tab. Here you
select From template code language and you can browse
code location as well.
Add SharePoint reference in your SharePoint
solution.
using
Microsoft.SharePoint;
Write following code to "FormEvents_submit"
event.
public
void FormEvents_Submit(object
sender, SubmitEventArgs e)
{
XPathNavigator root =
this.MainDataSource.CreateNavigator();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite
site = new SPSite("http://maaasdw002:3304"))
{
using (SPWeb web
= site.OpenWeb())
{
SPList list = web.Lists["CustInfo"];
SPListItem newItem = list.Items.Add();
newItem["Title"] = root.SelectSingleNode("/my:myFields/my:custTitle",
this.NamespaceManager).Value;
newItem["CustName"] = root.SelectSingleNode("/my:myFields/my:custName",
this.NamespaceManager).Value;
newItem["Age"] = root.SelectSingleNode("/my:myFields/my:Age",
this.NamespaceManager).Value;
newItem["Address"] = root.SelectSingleNode("//my:myFields/my:Address",
this.NamespaceManager).Value;
newItem.Update();
}
}
});
e.CancelableArgs.Cancel = false;
// Write your code here.
}
In the above code
XPathNavigator is an object to navigate
InfoPath
Step 2: (Creating Installable InfoPath Form Template)
From the design task pane click on "Publish Form Template". From publishing
wizard select first option to publish form in share point and click on next
button.
Enter the URL of SharePoint site and click on next button.
From the next window select "Administrator-approved form template" and click on
next button and click on Publish button to publish form.
Specify a location and file name for the form template and click on next - next
button and click on Publish button to publish the form.
Step 3: (Deploying InfoPath form in SharePoint)
Open Central Administrator go to "Application Management" and click on "Upload
Form template" from InfoPath Forms Services section
A new window will be open to upload form template. Browse the template location
and click on upload button to upload form template.
Now go to your SharePoint site settings and select "Site collection features".
Search your form template and click on Activate button to activate the form.
After activating form template go back to site settings page and select "Site
Libraries and lists" from the Site libraries and lists.
Select Form Templates Library and go to the form template library and click on
your template.
A new form will be open in the browser( to open form in the browser go to
Document Library settings>>Advance settings and select "display as a web page")
Fill the form and click on save data button to save data in the list.
Open "CustInfo" list to view your data.
In my next article I will explain how can How can we open info path forms inside
the SharePoint web page.
Thanks for reading...