I have a question. I maybe do something stupid on getting the api to work. In the past I worked with the nodefactory and umbraco 4.x in combination with the ucompontents and that worked fine.
Now I created an new project in VS2013, add cms.dll, businesslogic.dll and umbraco.dll as a reference and made the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.NodeFactory;
namespace pn_autoarchive
{
public partial class autoarchive1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Node myNode = new Node(1081);
string myValue = myNode.GetProperty("bodyText").Value;
string nodename = myNode.Name;
DateTime nodeCreationDate = myNode.CreateDate;
string url = myNode.NiceUrl;
Response.Write(myValue);
}
}
}
I put this code in a usercontrol and want to upload the usercontrol the a live umbraco 7 environment. When I build the solution I got this error:
An exception of type 'System.IO.FileNotFoundException' occurred in pn-autoarchive.dll but was not handled in user code
Additional information: Could not load file or assembly 'Umbraco.Core, Version=1.0.5211.22376, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
On
Node myNode = new Node(1081);
I think this error become forward because the usercontrol couldn't find Umbraco. But when I upload the usercontrol, and put it with a macro in an umbraco page, I got the following error:
[NullReferenceException: Object reference not set to an instance of an object.]
pn_autoarchive.autoarchive1.Page_Load(Object sender, EventArgs e) +179
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Control.LoadRecursive() +189
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177
I'm sure that the node ID exists.
I'm a little bit stuck, does anyone have a hint?
Thanks in advance.
It's because that with the release of v6 all API's where changed so you should not be using the nodefactory no more. Instead you should probably have a look at the "ContentService", which you can find more information about here http://our.umbraco.org/documentation/Reference/Management-v6/Services/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace pn_autoarchive
{
public partial class autoarchive1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// Get the Umbraco Content Service
var contentService = ApplicationContext.Current.Services.ContentService;
//Given a `ContentService` object get Content by its Id and get a value by alias
var content = contentService.GetById(1081);
object value = content.GetValue("bodyText");
string text = value as string;
}
}
}
And I got this error:
The given key was not present in the dictionary.
Is the code above right and what does the error mean?
Happy to help - What was the issue from the second post with code above using the new API? Others might benefit from the solution to this as well since the error message is quite common but is displayed for different reasons it seems.
Umbraco 7 + nodefactory
Hi,
I have a question. I maybe do something stupid on getting the api to work. In the past I worked with the nodefactory and umbraco 4.x in combination with the ucompontents and that worked fine.
Now I created an new project in VS2013, add cms.dll, businesslogic.dll and umbraco.dll as a reference and made the following code:
I put this code in a usercontrol and want to upload the usercontrol the a live umbraco 7 environment. When I build the solution I got this error:
On
I think this error become forward because the usercontrol couldn't find Umbraco. But when I upload the usercontrol, and put it with a macro in an umbraco page, I got the following error:
I'm sure that the node ID exists.
I'm a little bit stuck, does anyone have a hint? Thanks in advance.
Rik
Hi Rik
It's because that with the release of v6 all API's where changed so you should not be using the nodefactory no more. Instead you should probably have a look at the "ContentService", which you can find more information about here http://our.umbraco.org/documentation/Reference/Management-v6/Services/
You can learn more abot services and models as well here http://our.umbraco.org/documentation/Reference/Management-v6/Services/
I hope this helps.
/Jan
Hi Jan,
Thank you for your help!
I use this code at the moment:
And I got this error:
The given key was not present in the dictionary.
Is the code above right and what does the error mean?
best regards,
Rik
I fixed the problem. Thanks for your help!
Hi Rik
Happy to help - What was the issue from the second post with code above using the new API? Others might benefit from the solution to this as well since the error message is quite common but is displayed for different reasons it seems.
/Jan
Hi Jan,
I don't know for sure why the error was appearing. But I came up with this code:
And this works :)
Best regards,
Rik
is working on a reply...