Pre-Populate a SharePoint List Instance

So, you want to provide a look-up in a SharePoint Site Definition and you’d quite like to provide your users with some options? (i.e. items in the source list)

Firstly you’re probably interested in this post from Josh Gaffy about adding a lookup column declaratively using CAML.

Next you’ll be wanting to use this snippet to declare your source list and the data it will contain.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
	<ListInstance FeatureId="89CA0ED1-8E9B-48fa-8C4D-CB406544D662"
			TemplateType="100"
			Title="Option List"
			OnQuickLaunch="TRUE"
			Description="Choices"
			Url="Options" >
		<Data>
			<Rows>
				<Row>
					<Field Name="Title">Foo</Field>
				</Row>
				<Row>
					<Field Name="Title">Bar</Field>
				</Row>
				<Row>
					<Field Name="Title">Fred</Field>
				</Row>
				<Row>
					<Field Name="Title">Mildred</Field>
				</Row>
				<Row>
					<Field Name="Title">Karl</Field>
				</Row>
				<Row>
					<Field Name="Title">Lenny</Field>
				</Row>
			</Rows>
		</Data>
	</ListInstance>
</Elements>

Hope that someone finds this useful.

About these ads
This entry was posted in CAML, Development, SharePoint. Bookmark the permalink.

3 Responses to Pre-Populate a SharePoint List Instance

  1. Gary says:

    Thanks bro!

  2. Vivien Pipo says:

    thanks but I want to put values in a mutiple values field, I tried
    value1;value2;value3

    It does not work. Do you know How to complete that?

    • gavinbarron says:

      The default separator for multivalued items is ;# so value1;#value2;#value3;# may work for you. That said though if your multivalued item is a lookup to another list you’ll need to provide the ID of the item you’re looking up to as well as the value. I can’t recall the pattern for that off the top of my head but if you get stuck then inspect an item you created via the web ui using SharePoint Manager.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s