This is one of the missing commands in Sharepoint, get the first and the last element of a list really quickly. There is a way, of doing it with LINQ, but the performance is ridiculous, you don’t really want to go for the LINQ route.
What are the alternatives for this issue? well, we all know CAML is the fastest way, outside SQL to get data from Sharepoint, so let’s go to do it like this.
To get the last element of the list (in this case Title):
To get the first element of the list (in this case Title):SPQuery query = new SPQuery();query.RowLimit = 1;query.Query = "<OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>";SPListItemCollection listItemCollection = _spList.GetItems(query);//## GETTING THE LAST ITEM TO GET THE IDif (listItemCollection.Count > 0){if (listItemCollection[0]["Title"] != null){_iTitle = Convert.ToInt32(listItemCollection[0]["Title"]);_iTitle++;}}
SPQuery query = new SPQuery();query.RowLimit = 1;query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>";SPListItemCollection listItemCollection = _spList.GetItems(query);//## GETTING THE LAST ITEM TO GET THE IDif (listItemCollection.Count > 0){if (listItemCollection[0]["Title"] != null){_iTitle = Convert.ToInt32(listItemCollection[0]["Title"]);_iTitle++;}}
Conclusion: CAML still the fastest way to do queries in Sharepoint, just use your imagination and go for it!
2 comments:
christian louboutin
canada goose femme
timberland boots
kate spade sale
gucci handbags online
ed hardy outlet
nike roshe run shoes
cheap oakley sunglasses
clippers jerseys
adidas yeezy
2016.12.17xukaimin
JAMU-SUB, A.J. casino, restaurants, and entertainment
JAMU-SUB, titanium tubing A.J. casino, restaurants, and entertainment, entertainment 목포 출장안마 and 전라남도 출장마사지 hotel features a 전라북도 출장마사지 number of activities ranging from 동해 출장안마 a casual bar and lounge
Post a Comment