Ok, so adding to my previous question here - I want to get certain columns from a sharepoint list, then compare values of those columns to items in my own c# list and, if they're different, modify them.
This is what i got so far:
var web = SPContext.Current.Site.RootWeb;
SPList list = web.Lists["My Movie List"];
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='Movie WebID' />" +
"<FieldRef Name='url' />" +
"<FieldRef Name='rating' />";
query.Folder = list.ParentWeb.GetFolder("My Folder");
SPListItemCollection listItemCollection = list.GetItems(query);
foreach(SPListItem item in listItemCollection)
{
int itemID = movies.FindIndex(movie => movie.ID == item["Movie WebID"]);
if ( item["url"] != movies[itemID].URL1 || item["url"] != movies[itemID].RATING1)
{
item["url"] = movies[itemID].URL1;
item["rating"] = movies[itemID].RATING1;
item.Update();
}
}
Could somebody check if the syntax is correct and if there is a better way to write that code?
Also I'm confused about the item["rating"] field, as rating is an integer - is there some casting necessary then?