Tuesday, February 21, 2012

Q: How do I write to SharePoint lists using LINQ to SharePoint?

LINQ to SharePoint provides a terrific query facility, but it also makes it really easy to add and update list items.

From MSDN:  How to: Write to Lists Using LINQ to SharePoint

The particularly interesting code snippet:
// Create the new list item.
TeamMember bob = new TeamMember() { Title="Bob Smith" };

// Set the item to be inserted.
teamSite.TeamMembers.InsertOnSubmit(bob);

// Write changes to the content database.
teamSite.SubmitChanges();
Easy as that!

0 comments: