Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
i am going to write a method that implement on save and publish so i write a class that inherit from I Component
public class MyComponent : IComponent
and start to write my method
but i cant using umbraco.content() neither umbraco.media() in this class
how can i solve this problem ?
Have a look at this example in the documentation.
Essentially the 'Umbraco' in Umbraco.Content and Umbraco.Media is an instance of the UmbracoHelper class provided for convenience in Views, Controllers etc - but no so in a Component, where it cannot be guaranteed that an UmbracoContext will exist, the UmbracoHelper relies on their being an UmbracoContext.
In the example above you can see the use of the UmbracoContextFactory to ensure the context exists, to get a reference to the UmbracoContext to allow you to query the content or media caches.
IPublishedContentCache contentCache = umbracoContextReference.UmbracoContext.Content;
IPublishedContent soonToBeUnPublishedItem = contentCache.GetById(item.Id);
if that helps?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted