Freigeben über


HOW TO: Deploy InfoPath List Forms for an External List using Visual Studio 2012 solution package

This post is a contribution from Aaron Miao, an engineer with the SharePoint Developer Support team.

Create a test site

1. We create a SharePoint site collection named https://intranet.contoso.com/sites/testsite/testexternallist.

**It’s good to use a site which does not have lot of stuffs, best would be to create a new team site or blank site.

2. Activate the following site collection features:

     a. SharePoint Server Enterprise Site collection features

     b. SharePoint Server Standard Site collection features

Prepare SQL Database table

**You could use Northwind sample database

3. Create a table in SQL database called TestTable.

image

4. Add some data to it.

image

Create an external content type and a list instance using SharePoint Designer 2013

5. Open the test site using SPD 2013 and create an external content type ExternalTestCT (reference if you need it).

image

6. Create external list using SPD 2013 and choose to create InfoPath forms.

image

The result should look like this.

image

7. Verify external list works by browsing to it using SharePoint 2013 UI.

image

8. Make sure the external list displays data successfully in InfoPath forms.  “View Item” of the list will display an item in InfoPath form like this:

image

Prepare Visual Studio SharePoint 2013 project

9. Now save the site as template without content using SPD 2013.

image

10. This will generate a WSP file in your site collection solution gallery.  Download a copy of this WSP and save it to local disk.

image

Create Visual Studio 2013 project and solution

11. Create a Visual Studio 2013 project of type “SharePoint 2013 – Import Solution Package” and point to the saved WSP.  As a reference, this blog walks through the entire process.

image

**When there’s a warning about dependencies, click “Yes” to have VS 2012 automatically include all dependencies.

12. Once you are done with these steps, you will have the external list instance, with its schema.  You will also have Modules with all the InfoPath forms and template.xsn.  In addition, you’ll see a PropertyBags module as well.  Your project should look like this:

image

13. Clean up unnecessary files

       a. Remove ListsExternalList1_pages item

       b. Remove 2 features (3 features are imported.  Retain the first feature you see from the top in the list of features and remove the other 2)     

       c. Make sure the feature includes items: List instances, Modules and PropertyBags.

In the end, your project should look like this:

image

Details of each file

**Make sure you verify that the external list name is same in the list instance and all the files (schema, module files). There are lots of places the list name and its URL is used.

14. ExternalList1/Elements.xml:

 <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
     <ListInstance FeatureId="{00bfea71-9549-43f8-b978-e47e54a10600}" 
                 TemplateType="600" 
                 Title="ExternalList1" 
                 Description="" Url="Lists/ExternalList1" 
                 CustomSchema="Files\Lists\ExternalList1\Schema.xml" 
                 HyperlinkBaseUrl="https://spdev1505/sites/TestSite" 
                 RootWebOnly="FALSE" xmlns="https://schemas.microsoft.com/sharepoint/">
         <DataSource>
             <Property Name="Entity" Value="ExternalTestCT" />
             <Property Name="EntityNamespace" Value="https://spdev1505/sites/testsite" />
             <Property Name="LobSystemInstance" Value="testdb" />
             <Property Name="SpecificFinder" Value="Read Item" />
         </DataSource>
     </ListInstance>
 </Elements>

**<DataSource> provides information of the generated BDC model.

15. ExternalList1/Schema.xml:

 <List Title="ExternalList1" 
       Direction="none" 
       Url="Lists/ExternalList1" 
       BaseType="0" Type="600" 
       MultipleDataList="FALSE" 
       DontSaveInTemplate="TRUE" 
       DisableGridEditing="TRUE" 
       NoCrawl="TRUE" 
       DisallowContentTypes="TRUE" 
       BrowserFileHandling="permissive" 
       NavigateForFormsPages="TRUE" 
       FolderCreation="FALSE" 
       DisableAttachments="TRUE" 
       Catalog="FALSE" 
       SendToLocation="|" 
       ImageUrl="/_layouts/15/images/itebl.png?rev=23" 
       xmlns:ows="Microsoft SharePoint" 
       xmlns:spctf="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms" 
       xmlns="https://schemas.microsoft.com/sharepoint/">
     <MetaData>
         <Fields>
             <Field DisplayName="BDC Identity" Hidden="FALSE" Name="BdcIdentity" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="BdcIdentity" Type="Text" ReadOnly="TRUE" />
             <Field DisplayName="TextCol" Hidden="FALSE" Name="TextCol" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="TextCol" Type="Text" ReadOnly="TRUE" Required="TRUE" />
             <Field DisplayName="DateCol" Hidden="FALSE" Name="DateCol" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="DateCol" Type="DateTime" />
             <Field DisplayName="BoolCol" Hidden="FALSE" Name="BoolCol" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="BoolCol" Type="Boolean" />
         </Fields>
         <Forms />
         <Views>
             <View DisplayName="ExternalTestCT Read List" DefaultView="TRUE" BaseViewID="1" 
             Type="HTML" MobileView="TRUE" MobileDefaultView="TRUE" ImageUrl="/_layouts/15/images/generic.png?rev=23" 
             XslLink="main.xsl" WebPartZoneID="Main" WebPartOrder="0" Url="Read List.aspx" SetupPath="pages\viewpage.aspx">
                 <XslLink>main.xsl</XslLink>
                 <Method Name="Read List" />
                 <Query>
                     <OrderBy>
                         <FieldRef Name="TextCol" />
                     </OrderBy>
                 </Query>
                 <ViewFields>
                     <FieldRef Name="TextCol" ListItemMenu="TRUE" LinkToItem="TRUE" />
                     <FieldRef Name="DateCol" />
                     <FieldRef Name="BoolCol" />
                 </ViewFields>
                 <RowLimit Paged="TRUE">30</RowLimit>
                 <Aggregations Value="Off" />
             </View>
         </Views>
     </MetaData>
 </List>

**Type=”600” indicates this is an external list. Fields are defined in the schema.

16. Modules/ListsExternalListItem_/Files/Elements.xml:

image

17. PropertyBags/Elements.xml:

 <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
   <PropertyBag Url="Lists/ExternalList1/Item/template.xsn" ParentType="File" RootWebOnly="FALSE" 
                HyperlinkBaseUrl="https://spdev1505/sites/TestSite" 
                AlwaysCreateFolder="TRUE" 
                xmlns="https://schemas.microsoft.com/sharepoint/">
     <Property Name="ipfs_streamhash" Value="WilYbGIFAHARhhugf7kJzQlo447iT2RkT/siF5/CimI=" Type="string" />
     <Property Name="vti_streamschema" Value="66" Type="int" />
   </PropertyBag>
 </Elements>

**There are many properties in the file generated originally. Only the above two are required. Looks like they are related to InfoPath form activation and file persistence.

In the end, you should see the artifacts like in the VS 2012 project attached to this blog post.

Test the solution

18. Deploy the project to another site.  You may not see the external list in the quick launch.  Navigate to site contents and click the external list.  You should see the list and InfoPath item view form.

image

image

19. The view form URL should like like what’s shown below.  Notice that displayifs.aspx is used and not DispForm.aspx.

https://intranet.contoso.com/sites/TestSite/Lists/ExternalList1/Item/displayifs.aspx?ID=\_\_bk410047005600870047004300\&Source=http%3A%2F%2Fspdev1505%2Fsites%2FTestSite%2FLists%2FExternalList1%2FRead%2520List%2Easpx\&ContentTypeId=0x0\&RootFolder=%2Fsites%2FTestSite%2FLists%2FExternalList1

Hope this post was helpful!

Sample VS2012 project for download