Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umbraco check if node is still exist

Tags:

c#

umbraco

Hello how to check in Umbraco that node that i get by Id is still exist

var node = new Node(id);

return object in anyway, but if I try read some properties I got exception. Does anyone know Umbraco API function for check it ?

like image 753
Arbejdsglæde Avatar asked Jan 15 '12 08:01

Arbejdsglæde


2 Answers

I usually just check:

string.IsNullOrEmpty(node.Name)

A node should never have an empty name, so that way you know it's either unpublished or has been deleted.

It is a workaround for the fact that the API has no other way of checking this.

like image 110
sebastiaan Avatar answered Sep 22 '22 00:09

sebastiaan


I use your code to display name of node but when I unpublish it then i have "Error loading Razor Script" . I thought that it will be null.

I use below code in razor macro:

@{

    var main = @Model.Down(1);  

    string value = @main.Name.ToString();

    if(!string.IsNullOrEmpty(value)){
        @value
    }
} 

Working perfectly only when node is published

like image 21
user2039960 Avatar answered Sep 19 '22 00:09

user2039960