This is not easy. It took me some days. – Now it works!
Here I’ll show you how to create a List Form for a SharePoint List using InfoPath 2010. Therefore you need SharePoint 2010 Server with Enterprise CALs! – With InfoPath Forms Services it’s possible to render List Forms (“New”, “Edit” and “Display” forms) as browser enabled InfoPath forms. This is really, really cool!
I’ve published the project source code on Codeplex: http://spinfopathlistform.codeplex.com/
Lets start…
1. We create a SharePoint site collection named “http://sharepoint.local/sites/infopathlistform”.
2. Now we activate the site collection features:
- SharePoint Server Enterprise Site Collection features
- SharePoint Server Standard Site Collection features
The enterprise features need to be activated in order to get InfoPath Forms Services working.
3. Open Visual Studio 2010. Create an “Empty SharePoint Project” named “ik.SharePoint2010.InfoPathListFormDemo”.
Deploy them as “Farm Solution”.
4. Now we add a new project item of type “List Definition” named “Test List 1”.
We choose “Custom List” as base type and check “Add a list instance…”
5. We open the “Elements.xml” file of the List Instance.
We change the List Title and List URL.
6. We edit the “schema.xml” file.
We create a list content type with 3 fields.
Here you see the complete content of the “Schema.xml” file.
<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="Test List 1" FolderCreation="FALSE"
Direction="$Resources:Direction;"
Url="Lists/ik.SharePoint2010.InfoPathListFormDemo-TestList1"
Type="100"
BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<ContentTypes>
<ContentType ID="0x01009A15733A093E44C385EDB29F8E2E1B5A" Name="List Item" Inherits="false">
<Folder TargetName="Item" />
<FieldRefs>
<FieldRef ID="{10F8137D-B555-472C-8ACB-B64FF5BEAAF8}" Name="Field_1" />
<FieldRef ID="{84E33CDB-8DDC-4F46-BBF5-845D4071ED41}" Name="Field_2" />
<FieldRef ID="{52680EED-BE6F-478F-A6EC-730398CD626C}" Name="Field_3" />
</FieldRefs>
</ContentType>
<ContentTypeRef ID="0x0120" />
</ContentTypes>
<Fields>
<Field ID="{10F8137D-B555-472C-8ACB-B64FF5BEAAF8}" Name="Field_1" StaticName="Field_1"
DisplayName="Text Field" Type="Text"/>
<Field ID="{84E33CDB-8DDC-4F46-BBF5-845D4071ED41}" Name="Field_2" StaticName="Field_2"
DisplayName="DateTime Field" Type="DateTime" Format="DateOnly" />
<Field ID="{52680EED-BE6F-478F-A6EC-730398CD626C}" Name="Field_3" StaticName="Field_3"
DisplayName="Checkbox Field" Type="Boolean" />
</Fields>
<Views>
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitleNoMenu"></FieldRef>
<FieldRef Name="Field_1"></FieldRef>
<FieldRef Name="Field_2"></FieldRef>
<FieldRef Name="Field_3"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
</ParameterBindings>
</View>
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="Field_1"></FieldRef>
<FieldRef Name="Field_2"></FieldRef>
<FieldRef Name="Field_3"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="ID"></FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
</View>
</Views>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pagesform.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>
7. The next step is to add an “Empty Element” project item named “Fields”. We add the following content:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{10F8137D-B555-472C-8ACB-B64FF5BEAAF8}" Name="Field_1" StaticName="Field_1"
DisplayName="Text Field" Type="Text"/>
<Field ID="{84E33CDB-8DDC-4F46-BBF5-845D4071ED41}" Name="Field_2" StaticName="Field_2"
DisplayName="DateTime Field" Type="DateTime" Format="DateOnly" />
<Field ID="{52680EED-BE6F-478F-A6EC-730398CD626C}" Name="Field_3" StaticName="Field_3"
DisplayName="Checkbox Field" Type="Boolean" />
</Elements>
8. Now we deploy the project.
9. Open the site in the browser. Navigate to the “Test List 1”. Select “Edit in SharePoint Designer” from the “Site Actions” menu.
10. In SharePoint Designer 2010 open the “Lists and Libraries” from the “Navigation” pane and open the “Test List 1”.
In the Ribbon you’ll see the command “Design Forms in InfoPath”.
Click the command button and select “List Item” in the drop down menu.
Now InfoPath Designer 2010 opens…
11. In InfoPath Designer 2010 modify the form.
(I will not modify it.)
Press the “Publish” button on the Shortcut Menu:
12. In SharePoint Designer 2010 choose “All Files” from the “Navigation” pane. Click “Lists”.
Click “TestList1”.
Click “Item”.
Right-click “template.xsn”. Select “Properties…” from the context menu.
Select the “Location” from the properties dialog.
Copy the URL and open it in a new browser window. You’ll get a “File Download” dialog.
Save the file to a temporary location, e.g. to the Desktop.
13. Add a new “Module” project item and name it “Form”.
Open a Windows Explorer. Navigate to the Desktop. Drag the file “template.xsn” from the Desktop into the “Form” module inside the Visual Studio project.
Modify the “Elements.xml” file of the “Form” module.
14. Add a new “Module” project item and name it “FormPages”.
Into the “Elements.xml” file of this module enter the following code:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="TestList1Form" Url="Lists/TestList1/Item" SetupPath="pages" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/">
<File Url="displayifs.aspx" Type="Ghostable" Path="form.aspx">
<BinarySerializedWebPart>
<GUIDMap>
<GUID Id="1b8faa0c_4e13_43e7_981f_57d525170d09" ListUrl="Lists/TestList1" />
</GUIDMap>
<WebPart ID="{D95DEC48-6F9E-4961-BE47-380AD2870CCA}"
List="{$ListId:Lists/TestList1;}"
Type="4"
Url="Lists/TestList1/Item/displayifs.aspx"
WebPartOrder="0"
WebPartZoneID="Main"
IsIncluded="True"
FrameState="0"
WPTypeId="{b1dc92e2-8558-f555-ae81-35ed9ddf1644}"
Assembly="Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart"
AllUsers="B6Dt/iwAAAABAAAAAAAAAAEAAAB+bGlzdC9JdGVtL3RlbXBsYXRlLnhzbgD/ARQrABQCAgIDAgMBBAACAQIJAQEAAggFDEZvcm1Mb2NhdGlvbgUXfmxpc3QvSXRlbS90ZW1wbGF0ZS54c24FDUNvbnRlbnRUeXBlSWQFJjB4MDEwMDdEMTVFNzgxOUUwNDMzNEE4QkY5OTE3OEM1OUNDNjhDBQxMaXN0Rm9ybU1vZGULKaIBTWljcm9zb2Z0Lk9mZmljZS5JbmZvUGF0aC5TZXJ2ZXIuQ29udHJvbHMuV2ViVUkuTGlzdEZvcm1Nb2RlLCBNaWNyb3NvZnQuT2ZmaWNlLkluZm9QYXRoLlNlcnZlciwgVmVyc2lvbj0xNC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj03MWU5YmNlMTExZTk0MjljAQUOU3VibWl0QmVoYXZpb3ILKaQBTWljcm9zb2Z0Lk9mZmljZS5JbmZvUGF0aC5TZXJ2ZXIuQ29udHJvbHMuV2ViVUkuU3VibWl0QmVoYXZpb3IsIE1pY3Jvc29mdC5PZmZpY2UuSW5mb1BhdGguU2VydmVyLCBWZXJzaW9uPTE0LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTcxZTliY2UxMTFlOTQyOWMDAQAAAgICAgU+VXNlIHRoaXMgV2ViIFBhcnQgdG8gZGlzcGxheSBhbiBJbmZvUGF0aCBicm93c2VyLWVuYWJsZWQgZm9ybS4="
PerUser="/wEUKwAJAgICAwIBAQAAAgQChAELKjFTeXN0ZW0uV2ViLlVJLldlYkNvbnRyb2xzLldlYlBhcnRzLlBhcnRDaHJvbWVUeXBlAgIEBRZJbmZvUGF0aCBGb3JtIFdlYiBQYXJ0" />
</BinarySerializedWebPart>
</File>
<File Url="editifs.aspx" Type="Ghostable" Path="form.aspx">
<BinarySerializedWebPart>
<GUIDMap>
<GUID Id="1b8faa0c_4e13_43e7_981f_57d525170d09" ListUrl="Lists/TestList1" />
</GUIDMap>
<WebPart ID="{f811e526-1ad2-4563-b51b-4233f2641a33}"
List="{$ListId:Lists/TestList1;}"
Type="6"
Flags="0"
Url="Lists/TestList1/Item/editifs.aspx"
WebPartOrder="0"
WebPartZoneID="Main"
IsIncluded="True"
FrameState="0"
WPTypeId="{b1dc92e2-8558-f555-ae81-35ed9ddf1644}"
Assembly="Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart"
AllUsers="B6Dt/iwAAAABAAAAAAAAAAEAAAB+bGlzdC9JdGVtL3RlbXBsYXRlLnhzbgD/ARQrABICAgIDAgMBBAACAQIJAQEAAgYFDEZvcm1Mb2NhdGlvbgUXfmxpc3QvSXRlbS90ZW1wbGF0ZS54c24FDUNvbnRlbnRUeXBlSWQFJjB4MDEwMDdEMTVFNzgxOUUwNDMzNEE4QkY5OTE3OEM1OUNDNjhDBQ5TdWJtaXRCZWhhdmlvcgsppAFNaWNyb3NvZnQuT2ZmaWNlLkluZm9QYXRoLlNlcnZlci5Db250cm9scy5XZWJVSS5TdWJtaXRCZWhhdmlvciwgTWljcm9zb2Z0Lk9mZmljZS5JbmZvUGF0aC5TZXJ2ZXIsIFZlcnNpb249MTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49NzFlOWJjZTExMWU5NDI5YwMBAAACAgICBT5Vc2UgdGhpcyBXZWIgUGFydCB0byBkaXNwbGF5IGFuIEluZm9QYXRoIGJyb3dzZXItZW5hYmxlZCBmb3JtLg=="
PerUser="/wEUKwAJAgICAwIBAQAAAgQChAELKjFTeXN0ZW0uV2ViLlVJLldlYkNvbnRyb2xzLldlYlBhcnRzLlBhcnRDaHJvbWVUeXBlAgIEBRZJbmZvUGF0aCBGb3JtIFdlYiBQYXJ0" />
</BinarySerializedWebPart>
</File>
<File Url="newifs.aspx" Type="Ghostable" Path="form.aspx">
<BinarySerializedWebPart>
<GUIDMap>
<GUID Id="1b8faa0c_4e13_43e7_981f_57d525170d09" ListUrl="Lists/TestList1" />
</GUIDMap>
<WebPart ID="{7319002a-a547-4cdf-8acc-c5ba9cf8a6c9}"
List="{$ListId:Lists/TestList1;}"
Type="8"
Flags="0"
Url="Lists/TestList1/Item/newifs.aspx"
WebPartOrder="0"
WebPartZoneID="Main"
IsIncluded="True"
FrameState="0"
WPTypeId="{b1dc92e2-8558-f555-ae81-35ed9ddf1644}"
Assembly="Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart"
AllUsers="B6Dt/iwAAAABAAAAAAAAAAEAAAB+bGlzdC9JdGVtL3RlbXBsYXRlLnhzbgD/ARQrABICAgIDAgMBBAACAQIJAQEAAgYFDEZvcm1Mb2NhdGlvbgUXfmxpc3QvSXRlbS90ZW1wbGF0ZS54c24FDUNvbnRlbnRUeXBlSWQFJjB4MDEwMDdEMTVFNzgxOUUwNDMzNEE4QkY5OTE3OEM1OUNDNjhDBQ5TdWJtaXRCZWhhdmlvcgsppAFNaWNyb3NvZnQuT2ZmaWNlLkluZm9QYXRoLlNlcnZlci5Db250cm9scy5XZWJVSS5TdWJtaXRCZWhhdmlvciwgTWljcm9zb2Z0Lk9mZmljZS5JbmZvUGF0aC5TZXJ2ZXIsIFZlcnNpb249MTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49NzFlOWJjZTExMWU5NDI5YwMBAAACAgICBT5Vc2UgdGhpcyBXZWIgUGFydCB0byBkaXNwbGF5IGFuIEluZm9QYXRoIGJyb3dzZXItZW5hYmxlZCBmb3JtLg=="
PerUser="/wEUKwAJAgICAwIBAQAAAgQChAELKjFTeXN0ZW0uV2ViLlVJLldlYkNvbnRyb2xzLldlYlBhcnRzLlBhcnRDaHJvbWVUeXBlAgIEBRZJbmZvUGF0aCBGb3JtIFdlYiBQYXJ0" />
</BinarySerializedWebPart>
</File>
</Module>
</Elements>
During deployment this creates the form aspx pages that will host the InfoPath Web Part that renders the form at runtime.
In the XML code there are several references to the destination list. All of them have to be set to “Lists/TestList1”. All the code needs to remain unmodified. Don’t change “WPTypeId” attributes! “{b1dc92e2-8558-f555-ae81-35ed9ddf1644}” is the identifier for InfoPath Render Web Part.
BUT change the “ID” attributes of the three “WebPart” tags! Use the “Create GUID” tool from the “Tools” menu of Visual Studio 2010.
15. Now open the “Schema.xml” file of the List Definition project item of “Test List 1”. Add the following code at the before the closing tag of our list content type.
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display> ListForm</Display>
<Edit> ListForm</Edit>
<New> ListForm</New>
</FormTemplates>
</XmlDocument>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<Display> ~list/Item/displayifs.aspx</Display>
<Edit> ~list/Item/editifs.aspx</Edit>
<New> ~list/Item/newifs.aspx</New>
</FormUrls>
</XmlDocument>
</XmlDocuments>
16. Add another project item of type “Empty Element” named “PropertyBag”. Edit the “Elements.xml” file. Add this code:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag Url="Lists/TestList1/Item/template.xsn"
ParentType="File" RootWebOnly="FALSE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Name="ipfs_listform" Value="true" Type="string" />
<Property Name="ipfs_streamhash" Value="" Type="string" />
</PropertyBag>
</Elements>
This will define the “template.xsn” to be a “InfoPath Forms Services” file ().
17. Deploy the project.
18. Open the browser and navigate to the “Test List 1”.
Click “Add new item”…
19. HERE WE ARE!
But if you enter values and try to save you get this error:
This is caused by the missing “Title” field inside the form. This field is marked as mandatory so you need to define it or to remove it from the Content Type and modify the form.
We will do the last one now.
20. In Visual Studio modify the “schema.xml” file of the “Test List 1”. Insert the marked line of code inside the “FieldsRefs” tag of the content type with id starting “0x01…”.
Now search for “LinkTitleNoMenu” in the schema.xml file. Replace this “view field reference” with “Edit”.
Now search for “LinkTitle” and replace it with “Edit” too.
21. In Visual Studio look for “template.xsn” in “Form” path in the Solution Explorer. Right-Click the project item and select “Open Containing Folder”.
22. In Windows Explorer right-click the file “template.xsn” and click “Design”. The InfoPath 2010 Designer will open.
23. In InfoPath 2010 you’ll see that “Title” cannot be removed. To remove it you would need the edit the xsn file with Notepad: XSN is a CAB file. So you can rename it to cab, extract it’s content, modify the “manifest.xfs” file and compress the folder as CAB file named “template.xsn”… (If you need assistance on this please post as comment.)
In the “Fields” pane select “Title”.
(This is the “advanced view” !)
Click the arrow behind the element. Click “Properties” in the context menu.
Uncheck “Cannot be blank”. Click the “OK” button. Save the file. Don’t press “Publish” on the upcoming dialog. Just press “Save”!
Quit InfoPath.
Deploy the project.
24. In Internet Explorer refresh you site and add a new item to the “Test List 1”.
You’ll see: the “Title” column is gone. Now we have a “Edit item” column on the list view.
Now add an item.
Save it.
25. HERE WE ARE AGAIN!
It works for me now!
Just for testing purpose select the list item and click “View Item” on the Ribbon.
You will see the list item in a read-only InfoPath browser form!! – If you click “Edit” on the Ribbon, you’ll be able to edit the item.