Given a custom list with folders for countries:
ListA
---FolderA (Title: "USA")
------Item1
------Item2
------Item3
---FolderB (Title: "Switzerland")
------Item4
------Item5
------Item6
Given a new custom list with country names:
ListB
---Item1 (Title: "USA")
---Item2 (Title: "Switherland")
We have to move all Items in all folders to the root of the list. The Items contain a new Look-up field "Country" which looks up the ListB. When we move the items, it should set the lookupfield to the same as where the item was:
ListA
---Item1 (Lookupfield "Country" set to ID 1)
---Item2 (Lookupfield "Country" set to ID 1)
---Item3 (Lookupfield "Country" set to ID 1)
---Item4 (Lookupfield "Country" set to ID 2)
---Item5 (Lookupfield "Country" set to ID 2)
---Item6 (Lookupfield "Country" set to ID 2)
I don't need the finished code, just some generic hints.
What I have so far:
Get all items in the ListA, and check if it's not a folder:
if (item.Folder == null);
then get in which folder the item is:
item.Web.GetFolder(item.Url.Substring(0, item.Url.LastIndexOf('/')));
// I don't know if this works and I don't understand the solutions
// provided here http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/c0ca9f6b-ec1a-4e8d-b053-7969573370a4/
Update a Lookupfield from an item:
item[lookupFieldName] = ID;