Add tags to content part programmatically

Topics: Writing modules
Jul 2, 2012 at 7:55 AM

I'm working at module that creates blog posts using Orchard.Blogs.

I need to add tags to my newly created post. Well, OK, let's do like this:

post.As<TagPart>.CurrentTags .... hmm ... it's readonly. Seems I need to create TagPart manually and somehow attach to blog post?

Jul 2, 2012 at 7:57 AM

Inject ITagService. It has methods to update the tags.

Jul 2, 2012 at 9:04 AM
Edited Jul 2, 2012 at 9:05 AM

Thank you!
This code does the job:

// ITagService _tagService, BlogPostPart blogPost, List<string> tags

_tagService.UpdateTagsForContentItem(blogPost.ContentItem, tags);