I believe the problem is that you are trying to get a template by calling "ContentHelper.GetByNodeId()" method. You are passing a template ID to method GetByNodeId which expects to get a node ID. The method returns null because it can't find a node with the ID of your template and then when you call ".Name" property on the result, it fails with an "object not set.." error.
Ok, it looks like this problem is not related with the uSiteBuilder. What happens when you just call Node.GetCurrent() (getting the current Umbraco node without uSiteBuilder)?
Yes, it's because of that. There is no current node in the backend's control. You can use uSiteBuilder as following:
MyDocType doc = ContentHelper.GetByNodeId<MyDocType(123), where 123 is id of a node of MyDocType document type OR
DocumentTypeBase doc = ContentHelper.GetByNodeId(123), where 123 is node id. Then you test and cast doc object (e.g: if (doc is MyDocType) { mycodeType = (MyDocType)doc} )
ContentHelper.GetCurrentContent() error
I'm trying to get the current template name, yet ContentHelper.GetCurrentContent() causes an "object not set" error...
var templateName = ContentHelper.GetByNodeId(ContentHelper.GetCurrentContent().Template).Name;
What am I doing wrong?
Where exactly are you trying to do this? Can you provide a full stack trace?
I believe the problem is that you are trying to get a template by calling "ContentHelper.GetByNodeId()" method. You are passing a template ID to method GetByNodeId which expects to get a node ID. The method returns null because it can't find a node with the ID of your template and then when you call ".Name" property on the result, it fails with an "object not set.." error.
Ok this produces the same error...
var currentDocType = ContentHelper.GetCurrentContent();
Hold on...
I'm working on a User Control that appears in the back end - so it won't have any content!
Sorry
Ok, it looks like this problem is not related with the uSiteBuilder. What happens when you just call Node.GetCurrent() (getting the current Umbraco node without uSiteBuilder)?
You can try it with the following code:
umbraco.presentation.nodeFactory.Node node = umbraco.presentation.nodeFactory.Node.GetCurrent()
Which version of Umbraco are you using?
:) No problem
Same error:
Object reference not set to an instance of an object.
I think it's because i'm trying to do this from the back end. (It's a custom control being displayed on a content tab using the usercontrol wrapper).
Yes, it's because of that. There is no current node in the backend's control. You can use uSiteBuilder as following:
MyDocType doc = ContentHelper.GetByNodeId<MyDocType(123), where 123 is id of a node of MyDocType document type OR
DocumentTypeBase doc = ContentHelper.GetByNodeId(123), where 123 is node id. Then you test and cast doc object (e.g: if (doc is MyDocType) { mycodeType = (MyDocType)doc} )
is working on a reply...