Itay Shakury
Itay Shakury

Reputation: 11

SharePoint - insert list item into a folder using LINQ

I am trying to use the new LINQ notation to add an item into a folder. I can add the item to the root of the list with:

dataContext.MyList.InsertOnSubmit(mynewObject);

But I can't find a way to make it go inside a folder. I am trying to avoid instanciating SPWeb, or SPSite objects.

Thanks, Itay,

Upvotes: 1

Views: 1451

Answers (1)

Joe Capka
Joe Capka

Reputation: 562

What you need to do is use the Path property on the mynewObject. This property is present if you use SPMetal to generate the Linq classes.

I created a folder in my List called Folder1, and then I set the Path property like so:

mynewObject.Path = "/Lists/MyList/Folder1";

Then call the InsertOnSubmit method as usual and your item will be in the right folder! I am not yet sure how to create the folder through linq, and do note that exceptions are thrown if the folder is not there.

Upvotes: 1

Related Questions