I am writing a small app that links into Umbraco (a small stand-alone console application that will eventually run as a scheduled task on the server) and I'm using the Umbraco APIs (4.5.2) to make changes to the database/document.
However I always get a NullReferenceException because there are no properties. This confuses me because I can see that there are 5 properties in the umbraco interface.
A colleague suggested that I use a Node instead of a document, however I can't even create one as I get a NullReferenceException from the Node class constructor.
Node myNode = new Node(-1); // NullReferenceException here
Is the code running in the Umbraco application or in a separate application? If it is the latter then you will probably run into some trouble trying it that way, and it would actually not be a good idea to 'share' the database etc. this way. A good idea would probably be to write custom web services which your custom application can then connect to to get the data. Here is what I have been using in one Umbraco app to traverse the whole tree:
Document[] roots = Document.GetRootDocuments();
foreach (Document doc in roots) {
if (doc.ContentType.Alias == "Homepage" && doc.HasChildren) {
//add all matched documents to the docList
AddDocumentsRecursive(doc);
}
}
There are probably better ways of achieving this in code, yet that is hard to tell as I don't know what you actually want to do.
Umbraco Document.getProperty().Value throws Null Reference Exception
I am writing a small app that links into Umbraco (a small stand-alone console application that will eventually run as a scheduled task on the server) and I'm using the Umbraco APIs (4.5.2) to make changes to the database/document.
Here is a fragment of what I'm doing:
However I always get a NullReferenceException because there are no properties. This confuses me because I can see that there are 5 properties in the umbraco interface.
A colleague suggested that I use a Node instead of a document, however I can't even create one as I get a NullReferenceException from the Node class constructor.
Does anyone have any ideas?
Hi Colin,
Is the code running in the Umbraco application or in a separate application? If it is the latter then you will probably run into some trouble trying it that way, and it would actually not be a good idea to 'share' the database etc. this way. A good idea would probably be to write custom web services which your custom application can then connect to to get the data. Here is what I have been using in one Umbraco app to traverse the whole tree:
Document[] roots = Document.GetRootDocuments();
foreach (Document doc in roots) {
if (doc.ContentType.Alias == "Homepage" && doc.HasChildren) {
//add all matched documents to the docList
AddDocumentsRecursive(doc);
}
}
There are probably better ways of achieving this in code, yet that is hard to tell as I don't know what you actually want to do.
Hope that helps,
Sascha
is working on a reply...