Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Following are few of the things that I used using Sharepoint 2007 (MOSS) object model, so if you want to programmatically create a list, delete items from the list, etc.
Deleting all items inside List:
SPWeb web = SPContext.Current.Web;
SPList myList = web.Lists ["List_Name"];
SPListItemCollection myListColl = web.Lists["List_Name "].Items;
web.AllowUnsafeUpdates = true;
for (int i = myListColl.Count - 1; i >= 0; i--)
{
myListColl [i].Delete();
}web.Update();
Creating a Sharepoint List: (I am just covering one type you can try other types)
SPWeb web = SPContext.Current.Web;
web.AllowUnsafeUpdates = true;
// Creating a Sharepoint List and adding Sharepoint Fields SPField to it
web.Lists.Add("AllUserWebpart_SiteUserinfo", "For User of the site", SPListTemplateType.GenericList);
web.Lists["AllUserWebpart_SiteUserinfo"].Fields.Add("Job Title", SPFieldType.Text, false);
web.Lists["AllUserWebpart_SiteUserinfo"].Fields.Add("Department", SPFieldType.Text , false);
web.Lists["AllUserWebpart_SiteUserinfo"].Fields.Add("Phone", SPFieldType.Text, false);
userInfoList = web.Lists["AllUserWebpart_SiteUserinfo"];
//Following code allows you to change the Title of the TITLE field which is added by default whenever you create a //Sharepoint List
SPField TitleField = userInfoList.Fields["Title"];
TitleField.Title = "Name";
TitleField.Update();
//Adding the fields to Default view (If you are adding your own view change the name of the view instead of "All Items"
SPView view = userInfoList.Views["All Items"];
SPViewFieldCollection viewFields = view.ViewFields;
viewFields.Add("Job Title");
viewFields.Add("Department");
viewFields.Add("Phone");
view.Update();
web.Update();
Comments
- Anonymous
February 06, 2008
PingBack from http://msdnrss.thecoderblogs.com/2008/02/07/sharepoint-2007-moss-sp-list-operations-using-object-model-progrmatically/