Example:
If you would like to delete item from SPListItemCollection by property name, you can do this by for loop with current statement below.
public void DeleteLinkItems(String Name)
{
SPList userList = GetUsersSPList ();
SPListItemCollection listItems = userList.Items;
for (int i=listItems.Count-1; i>-1; i--)
SPListItem item = listItems;
if(item["User"].ToString() == Name)
listItems.Delete(i);
}
private SPList GetUsersSPList()
//Get the site object
SPSite site = new PSite(“http://localserver/sites/UserList”);
// Get the web object
SPWeb userList = site.OpenWeb();
// Get User list object
return userList.Lists["User List Item"];
SPSite mySiteDR = new SPSite(myActionParentListURL);SPWeb myWebDR = mySiteDR.OpenWeb();
myWebDR.AllowUnsafeUpdates = true;SPList spListForDeletion = myWebDR.Lists["Listname"];
SPQuery myActionDeleteQuery = new SPQuery(); strCurrentUserName = myWebDR.CurrentUser.Name.ToString();
string myActionDeleteCAML = ""; myActionDeleteCAML = "<Where><And><Eq><FieldRef Name='Author' /><Value Type='User'>";myActionDeleteCAML = myActionDeleteCAML + strCurrentUserName+"</Value></Eq><IsNull><FieldRef Name='Title' /></IsNull></And></Where>";myActionDeleteQuery.Query = myActionDeleteCAML.ToString();
SPListItemCollection myActionItemCollectionDR = spListForDeletion.GetItems(myActionDeleteQuery);strMyActionDRCnt = myActionItemCollectionDR.Count;
if (strMyActionDRCnt > 0){
for (int dRowCnt = 0; dRowCnt < strMyActionDRCnt; dRowCnt++){ SPListItem item = myActionItemCollectionDR[dRowCnt]; myActionItemCollectionDR.Delete(dRowCnt); }}
//---------->Please refer this url too http://msdn2.microsoft.com/en-us/library/ms467435.aspx?PHPSESSID=ca9tbhkv7klmem4g3b2ru2q4d4
Regards,
Kapiljith.R
Copyright© 2008 Telligent Systems Inc. All rights reserved CommunityServer.com • Telligent.com