This project is read-only.

List Content Items by User

Topics: General, Writing modules
Jun 8, 2011 at 10:39 PM

I created a custom content part. Namely "Bookpart". And then I created a custom content type named "Book" which includes Bookpart and Commonpart.

I have no problems with adding contents.

Now, I would like to get the list of the books created by a specific user in my module. How can I do that with ContentManager.Query?

Thank you.

Jun 9, 2011 at 10:02 AM

I think it's:


Jun 9, 2011 at 8:08 PM
Edited Jun 9, 2011 at 8:09 PM


CommonPartRecord has OwnerId property which returns an integer. However I get my current user with orchardServices.WorkContext.CurrentUser which returns an IUser.

Other suggestions?

Jun 9, 2011 at 8:33 PM

Oh okay, I found that I have to use it like this:

Orchard.Security.IUser currentUser = _orchardServices.WorkContext.CurrentUser;

_contentManager.Query("Book",VersionOptions.Published).Where<CommonPartRecord>(c=>c.OwnerId == currentUser.Id);

Thank you pete!
Jun 9, 2011 at 9:14 PM

Oh yeah, I should have remembered it's an Id property. Anyway you found it!