using Umbraco.Web;
using Umbraco.Core.Models;
UmbracoHelper umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
IPublishedContent media = umbracoHelper.TypedMedia(imageId);
string cropUrl = media.GetCropUrl("My Crop Name");
(corrected formatting, can't seem to edit my post!)
Using Umbraco methods in external .cs file
Hi everyone,
I'm using an external .cs file in my App_Code folder for some classes and I just wondered if it's possible to use any Umbraco methods from this file?
So for example, I have an Image property for one of my classes, and I'd like to return a crop of that image instead of the full url. Is this possible?
Thanks
Hi,
You can access the Umbraco Helper as long as you''re running your code in the Umbraco application - check out https://our.umbraco.org/documentation/reference/querying/UmbracoHelper/ for more info.
Here's the code you would need to get the Crop URL of a media item:
Thanks,
Maff
Thanks Maff! That works perfectly.
For anyone else with the same problem, here's what I used:
using Umbraco.Web;
using Umbraco.Core.Models;
UmbracoHelper umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current); IPublishedContent media = umbracoHelper.TypedMedia(imageId); string cropUrl = media.GetCropUrl("My Crop Name");
(corrected formatting, can't seem to edit my post!)
Cool - glad to help! :)
is working on a reply...