The following code can be used to create a custom list in MOSS and apply a custom view to it:
// create list
web.Lists.Add(listName, "", SPListTemplateType.GenericList);
list = web.Lists[listName];
// Add your fields to the list
list.Fields.Add("Field1", SPFieldType.Text, false);
list.Fields.Add("Field2", SPFieldType.Text, false);
// You can change the title of a field by accessing the SPField object
SPField field1 = list.Fields["Field1"];
field1.Title = "Title Of Field 1";
field1.Update();
// You have to use a specialized string collection to add fields to a view
System.Collections.Specialized.StringCollection strCol = new System.Collections.Specialized.StringCollection();
strCol = new System.Collections.Specialized.StringCollection();
strCol.Add("Field1");
strCol.Add("Field2");
// You can use a standard query here to only return certain data
string query = string.Empty;
query = "";
SPView view = null;
view = list.Views.Add("Items Sorted By Field1", strCol, query, 20, true, false);
list.Update();
출처: http://www.sharepointblogs.com/mykiep/archive/2007/02/26/creating-a-list-with-a-custom-view-in-moss.aspx
댓글 영역