5

I am trying to get the link of a Page based on tcmUri:

var linkFactory = DependencyResolver.Current.GetService<LinkFactory>();
var link = linkFactory.ResolveLink("tcm:199-279055-64");

The Page is published, but link is always null, what I am doing wrong?

8

As already answered by Rob and Quirijn, the LinkFactory from DD4T only does Component Linking. You can use the core Tridion Content Delivery API to page link though. Check the Tridion.ContentDelivery.Web.Linking.PageLink class and it's various GetLink methods.

i.e:

 //create a new PageLink instance for publication 199
 var pageLink = new PageLink(199);

 //resolve the link
 var link = pageLink.getLink(279055);

 if (link.IsResolved) {
   ...
 }
8

The LinkFactory does Component Linking and it looks like you're trying to link to a Page.

Your link variable is null because there isn't a Component with that ID.

  • Ok, sounds obvious, is there an counterpart for Pages ? – Giu Do Nov 12 '13 at 15:27
  • 1
    There is page linking in the Tridion API but DD4T does not expose it. You typically know the URL before you get the page, and you use the URL to find the page rather than the other way around. – Quirijn Nov 12 '13 at 15:34

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.