Listing 3. Create the SharePoint List
static void Main(string[] args) {
Lists listService = _ListHelper.GetListsService();
//////////////////////////////////////////////////////////
// Create The Suppliers List
//////////////////////////////////////////////////////////
string strSuppliersFieldsInnerXml =
"<Method ID='1' AddToView=''>" +
"<Field Type='Number' DisplayName='SupplierID' Required='TRUE' /></Method>" +
"<Method ID='2' AddToView=''><Field Type='Text'" +
"DisplayName='CompanyName' Required='TRUE' MaxLength='255' /></Method>";
string strSuppliersGuid;
XmlNode nodeInsertSuppliersResult;
// create list will delete the list if it exists,
//
and recreate it with the fields specified.
//
All list items will be deleted.
ListHelper.CreateList(
listService, "Suppliers", "Companies that supply products to Northwind",
strSuppliersFieldsInnerXml, out strSuppliersGuid,
out nodeInsertSuppliersResult);
Console.WriteLine(nodeInsertSuppliersResult.OuterXml);
//////////////////////////////////////////////////////////
// Create The Products List
//////////////////////////////////////////////////////////
string strProductsFieldsInnerXml =
"<Method ID='1' AddToView=''><Field Type='Number' DisplayName='ProductID'" +
"Required='TRUE' /></Method>" +
"<Method ID='2' AddToView=''><Field Type='Text'" +
"DisplayName='ProductName' Required='TRUE' MaxLength='255' /></Method>" +
"<Method ID='3' AddToView=''><Field Type='Lookup' List='" + strSuppliersGuid
+
"' DisplayName='Supplier' Required='TRUE' /></Method>" + "";
string strProductsGuid;
XmlNode nodeInsertProductsResult;
// create list will delete the list if it exists,
//
and recreate it with the fields specified.
//
All list items will be deleted.
ListHelper.CreateList(listService, "Products",
"Goods received from suppliers and sold to customers.",
strProductsFieldsInnerXml, out strProductsGuid,
out nodeInsertProductsResult);
39
Putting SharePoint to Work for You, an Internet.com Developer eBook. Copyright 2008, Jupitermedia Corp.
Putting SharePoint to Work for You
[
]