Search code examples
c#xmlsharepoint-2010

How to add list column to list instance without list definition?


List Instance Elements.xml file:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="listname"
                OnQuickLaunch="TRUE"
                TemplateType="100"
                FeatureId="00bfea71-de22-43b2-a848-xxXxxxXxx"
                Url="Lists/listname"
                Description="">
  </ListInstance>
</Elements>

It is possible to add column only with this one file avaible? Or am I forced to use list definition ?


Solution

  • add a new file to the list instance named Schema.xml.
    put the code :

    <?xml version="1.0" encoding="utf-8" ?>
    <List xmlns:ows="Microsoft SharePoint" Title="listname" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/listname" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
      <MetaData>
        <ContentTypes>
          <ContentType ID="0x01" Name="Item" Group="List Content Types" Description="Create a new list item."  Overwrite="TRUE" FeatureId="{d725a6e2-53f9-40f6-897a-d0e6a05f9588}">
            <Folder TargetName="Item" />
            <FieldRefs>
              <FieldRef Name="LinkTitleNoMenu"></FieldRef>
              <FieldRef Name="LinkTitle"></FieldRef>
              <FieldRef Name="Title"/>
              <FieldRef ID="{07BCD344-0A65-4201-BB9F-302C52EA326C}" Name="User" DisplayName="User"/>
            </FieldRefs>
          </ContentType>
        </ContentTypes>
        <Fields>
          <Field ID="{2C5C4E9D-91D8-4995-8B08-20F323E42DF2}" Name="LinkTitle" DisplayName="Title" Type="Text"></Field>
          <Field ID="{D9B62993-78E7-45D0-BD1A-5DAE2C87E84A}" Name="LinkTitleNoMenu" DisplayName="Title" Type="Text"></Field>
          <Field ID="{34124B16-F636-4894-92C1-22BDCAA6FAFE}" Name="Title" DisplayName="Title" Type="Text" Required="TRUE"></Field>
          <Field ID="{07BCD344-0A65-4201-BB9F-302C52EA326C}" Name="User" DisplayName="User" Type ="Text"></Field>
        </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 ID="{07BCD344-0A65-4201-BB9F-302C52EA326C}" Name="Value" DisplayName="Value"/>
            </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="LinkTitle"></FieldRef>
              <FieldRef ID="{07BCD344-0A65-4201-BB9F-302C52EA326C}" Name="User" DisplayName="User"/>
            </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="pages\form.aspx" WebPartZoneID="Main" />
          <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
          <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
        </Forms>
      </MetaData>
    
    </List>
    <br/>
    

    don't change the 3 fields LinkTitle,LinkTitleNoMenu,Title.
    add new fields under user and change the GUID of newly added fields.
    change the properties of Schema.xml file as in the image.
    enter image description here