If I want to read this data with node.GetProperty(emailCompany).Value I always get null back. I looked into the source code how this data is load:
In the Node constructor:
// load data
foreach (XmlNode n in _pageXmlNode.SelectNodes("./data"))
_properties.Add(new Property(n));
Property constructor:
public Property(XmlNode PropertyXmlData) {
if (PropertyXmlData != null) {
// For backward compatibility with 2.x (the version attribute has been removed from 3.0 data nodes)
if (PropertyXmlData.Attributes.GetNamedItem("versionID") != null)
_version = new Guid(PropertyXmlData.Attributes.GetNamedItem("versionID").Value);
_alias = PropertyXmlData.Attributes.GetNamedItem("alias").Value;
_value = xmlHelper.GetNodeValue(PropertyXmlData);
} else
throw new ArgumentNullException("Property xml source is null");
}
It doens't look in the elements inside the data element. What is the best way to load this data? Should I just read the umbraco.config file directly or create a class which inhertis from Node and do some coding in there to fetch the data. Has anyone else had this before?
That would be a good idea, but the problem is I need the xml data from the node. This is stored inside private XmlNode _pageXmlNode; and since it's private I can't reach it. I think it's best to create my own class similar to the Node class, but with an method called GetPropertyXml which loads the property as xml. This might acutally be good for the default umbraco Node object. Will this problem be solved in 4.1 with Linq to Umbraco?
what db type are you using for your custom datatype? I think there's a difference in using ntext or nvarchar (don't remember by heart, but think one stores the value as is, the other as a cdata section? Maybe that can help?
The db type is an ntext. If I use an nvarchar I get an error because the stored xml is too big. Eventually I solved it with the following code:
//Get the current xml node.
XmlNode n = ((IHasXmlNode)library.GetXmlNodeCurrent().Current).GetNode();
//Convert the current xml node to a XDocument;
XDocument xmlDocument = XDocument.Load(new XmlNodeReader(n));
Once I have the xmlDocument I use LINQ to XML to get the data I need.
node.GetProperty on a custom datatype
Hello,
I've got a custom datatype which saves the value as an xml file inside the umbrac.config file. Here is an example:
If I want to read this data with node.GetProperty(emailCompany).Value I always get null back. I looked into the source code how this data is load:
In the Node constructor:
Property constructor:
It doens't look in the elements inside the data element. What is the best way to load this data? Should I just read the umbraco.config file directly or create a class which inhertis from Node and do some coding in there to fetch the data. Has anyone else had this before?
Jeroen,
If you are on .net35 may be try extension method see Darrens tip http://www.darren-ferguson.com/2010/2/25/quick-tip-using-extension-methods-with-umbraco-and-net-35.aspx write your own which can handle the custom datatype xml?
Regards
Ismail
Hi Ismail,
That would be a good idea, but the problem is I need the xml data from the node. This is stored inside private XmlNode _pageXmlNode; and since it's private I can't reach it. I think it's best to create my own class similar to the Node class, but with an method called GetPropertyXml which loads the property as xml. This might acutally be good for the default umbraco Node object. Will this problem be solved in 4.1 with Linq to Umbraco?
Jeroen
Jeroen,
what db type are you using for your custom datatype? I think there's a difference in using ntext or nvarchar (don't remember by heart, but think one stores the value as is, the other as a cdata section? Maybe that can help?
Cheers,
/Dirk
The db type is an ntext. If I use an nvarchar I get an error because the stored xml is too big. Eventually I solved it with the following code:
Once I have the xmlDocument I use LINQ to XML to get the data I need.
is working on a reply...