2

I need to resolve the real URL for an image (multimedia component) only knowing its tcm-uri and the publication id.

I've tried this way:

        var uri = new TcmUri("tcm:13-5093");
        var binaryLink = new BinaryLink(13);
        var link = binaryLink.GetLink(uri.ToString(), "", "", "", false);

        if (link.IsResolved)
            var image = link.Url;

but my link variable results always unresolved. I've also tried this way:

BinaryMetaFactory binaryMetaFactory = new BinaryMetaFactory();
BinaryMeta binaryMeta = binaryMetaFactory.GetBinaryMeta("tcm:13-5093");

if(binaryMeta!=null) {
    Response.Write("Path of the binary: " + binaryMeta.UrlPath);
}

But even this was not a good solution. My multimedia components are all correctly published so I don't have any idea. Can anyone help me?

2

It looks like uri.ToString() is converting as ItemId. Hence it's not resolving.

Try this way by passing full TCM ID:

String binaryUrl = String.Empty;
BinaryLink binaryLink = new BinaryLink(13);
Link link = binaryLink.GetLink("tcm:13-5093", "", "", "", false);
if (link != null && link.IsResolved)
{
    binaryUrl = link.Url;
}
  • Hi Siva, thank you for your answer. I've tried your way using a random image found on my website and it worked, then I've tried again my way with the same "random" image and it worked too. Actually, I really really don't know why, it seems working randomly only for some images. I point out that all the images I've tried are published and used somewhere across the site (also they are all jpeg images with no special metadata or something) but for some reason someone is resolved and someone not. – TommO May 29 '14 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.