1

I've created my first custom Umbraco 5.1 solution. At this point I have a content item ("homepage") with a custom template which has a custom partial macro on it. Now how do I load an entity using the Umbraco helper? I've tried adding several HiveId constructions using a Uri, however I keep getting the same error:

Parameter 'other' must be of type Guid to convert to a Guid CLR type, but it is 'Uri', with value: xxx

Macro partial:

@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework

@{
    //All these fail with the same error message...

    //Based on name:
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("content://Homepage")));

    //Based on path
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("content://p__nhibernate/v__guid/5a4abe489a2e47858bd2a0580180b683")));

    //With custom Hive provider (I've added this using a custom tree/section and products show up, so the hive provider works)
    var p = Umbraco.GetContentById(
      new HiveId(
        new Uri("custom://products/1")));
}

Ropstah
  • 17,538
  • 24
  • 120
  • 194

1 Answers1

1

Why are you creating a Uri?
The HiveId accepts a string parameter which you can use instead. So does Umbraco.GetContentById(string id)

I am Umbraco 5 certified and we never used the Uri overload of the HiveId constructor.

var p = Umbraco.GetContentById("yourStringHiveIdHere"); //(string overload) or 
var p = Umbraco.GetContentById(new HiveId("yourSringHiveIdHere")); // (HiveId overload)

Also where are you getting your HiveId from?

Marko
  • 71,361
  • 28
  • 124
  • 158
  • Hmm, ok the first one works, however when I use the `HiveId` overload it doesn't... Also the first one doesn't work for my custom `HiveProvider`. It should just take a "data uri" right? – Ropstah May 21 '12 at 22:05
  • 1
    @Ropstah I have Umbraco open and just tested both and both worked for me. Is there a reason why you'd use a Data Uri instead of a string/hiveid? – Marko May 21 '12 at 22:08
  • I must have missed something because they indeed both work... I don't want to go off-topic too much, but what I'd really want is just to query my custom Hive provider using the Helper. I just have no idea on how to get the "Uri" to my entity (i do have a custom tree which show my custom hive provider data in the backoffice)... – Ropstah May 21 '12 at 22:15
  • 1
    @Ropstah I would imagine that it's something inside your custom hive provider and having to use the URI internally. Why not inspect the Umbraco source on CodePlex? i.e. http://umbraco.codeplex.com/SourceControl/changeset/view/382fea02040e#Source%2fLibraries%2fUmbraco.Hive%2fConfiguration%2fUriMatchElement.cs – Marko May 21 '12 at 22:18
  • I thought I could just use the `uri-matches` configuration to make `GetContentById("mycustom://uri/someid")` call `MyProvider.EntityRepository.PerformGet()`. Guess it's not that easy? – Ropstah May 21 '12 at 22:22
  • @Ropstah I'm not quite sure TBH. I would post another question regarding custom Hive Providers and probably put it on the Umbraco forums. v5 is still new and am not sure if the devs monitor SO, but they definitely monitor the Umbraco Forums. – Marko May 21 '12 at 22:27