Tuesday, August 28, 2012

to make a list instance in a 2010 SharePoint project...

In Visual Studio, I first, in the global Elements.xml, added a ContentType called "LocationTypes" which had just one FieldRef referencing a Text type Field called "TypeOfLocation." I then followed these steps:

  1. At the Solution Explorer, the right-clicked and picked: Add > New Item...
     
  2. I picked "List Definition From Content Type" from the menu that popped up. This will create BOTH a List which is sort of a template/definition for an instantiation AND an actual instantiation called a List Instance.
     
  3. I went through a brief wizard. I picked a content type and gave a friendly name for the list. The list was created with a list instance nested inside of it.
     
  4. The Elements.xml inside of the instance looks like the following. Some of this was generated, but some of this I doctored up. I manually added the four rows and I manually changed the Title value to something easy on the eye.
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       <ListInstance Title="Location Types"
                            OnQuickLaunch="TRUE"
                            TemplateType="10000"
                            Url="Lists/SharePoint.FSC.AOPC-ListInstance1"
                            Description="My List Instance">
          <Data>
             <Rows>
                <Row>
                   <Field Name="TypeOfLocation">Area</Field>
                </Row>
                <Row>
                   <Field Name="TypeOfLocation">MSN</Field>
                </Row>
                <Row>
                   <Field Name="TypeOfLocation">Office#</Field>
                </Row>
                <Row>
                   <Field Name="TypeOfLocation">VISN</Field>
                </Row>
             </Rows>
          </Data>
       </ListInstance>
    </Elements>

     
  5. In Schema.xml for the list itself I changed this...
    <ViewFields>
       <FieldRef Name="Attachments">
       </FieldRef>
       <FieldRef Name="LinkTitle">
       </FieldRef>
    </ViewFields>

    ...to this...
    <ViewFields>
       <FieldRef Name="TypeOfLocation">
       </FieldRef>
    </ViewFields>

    ...in order to ensure that my column was unhidden at the list instance and not the default columns.

No comments:

Post a Comment