<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fredrik Haglund's blog &#187; DynamicProperty</title>
	<atom:link href="http://blog.fredrikhaglund.se/blog/tag/dynamicproperty/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fredrikhaglund.se</link>
	<description>Chatter about EPiServer, ASP.NET, CSS and Web Development.</description>
	<lastBuildDate>Tue, 28 Jun 2011 13:37:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Access Dynamic Properties when PageData is writable</title>
		<link>http://blog.fredrikhaglund.se/blog/2008/05/28/access-dynamic-property/</link>
		<comments>http://blog.fredrikhaglund.se/blog/2008/05/28/access-dynamic-property/#comments</comments>
		<pubDate>Wed, 28 May 2008 10:34:24 +0000</pubDate>
		<dc:creator>Fredrik Haglund</dc:creator>
				<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[CreateWritableClone]]></category>
		<category><![CDATA[Dynamic Property]]></category>
		<category><![CDATA[DynamicProperty]]></category>
		<category><![CDATA[DynamicPropertyTree]]></category>
		<category><![CDATA[EPiServer 5]]></category>
		<category><![CDATA[FindDynamicProperty]]></category>

		<guid isPermaLink="false">http://blog.fredrikhaglund.se/?p=153</guid>
		<description><![CDATA[One of the big changes between EPiServer CMS 4 and 5 is the handling of PageData instances and Dynamic Properties (read Inherited Property) in the cache. I was reminded of this when I created a custom property and needed access to a Dynamic Property but I always got a null value. In EPiServer CMS 5 [...]]]></description>
			<content:encoded><![CDATA[<p>One of the big changes between EPiServer CMS 4 and 5 is the handling of PageData instances and Dynamic Properties (read Inherited Property) in the cache. I was reminded of this when I created a custom property and needed access to a Dynamic Property but I always got a null value.</p>
<p>In EPiServer CMS 5 you will always get a read-only PagaData instance and if you want to modify it you have to call <em>CurrentPage.<strong>CreateWritableClone</strong>(</em>) to get an instance that you can modify.</p>
<h3>Read Dynamic Propety value returns null</h3>
<p>On the read-only version you can always write <em>CurrentPage["MyDynamicProperty"]</em> or <em>CurrentPage.Property["MyDynamicProperty"]</em> to easily get hold of the inherited value. But if you try to do that on a writable <em>PageData</em> instance it will not work and you will always get null back.</p>
<p>In my case when I want the value of a dynamic property in a custom property controller it always returned null because in when you are editing the page your PageData instace is writable.</p>
<h3>Using DynamicPropertyTree to FindDynamicProperty</h3>
<p>You can retreive the value of a Dynamic Property with the same method that a read-only PageData use if you need it while modifying a page. </p>
<p><span style="font-size: x-small; color: #008080;">PageReference</span><span style="font-size: x-small;"> locationRef = </span><span style="font-size: x-small; color: #008080;">DynamicPropertyTree</span><span style="font-size: x-small;">.Instance.FindDynamicProperty(</span><span style="font-size: x-small; color: #800000;">&#8220;MyDynamicProperty&#8221;</span><span style="font-size: x-small;">, CurrentPage.Property).Value </span><span style="font-size: x-small; color: #0000ff;">as</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #008080;">PageReference<span style="color: #000000;">;</span></span></p>
<h3>Change a Dynamic Property from code</h3>
<p>If you need to change a Dynamic Property from code use the class EPiServer.DataAbstraction.DynamicProperty:</p>
<pre>DynamicProperty myDynProp = DynamicProperty.Load(CurrentPage.PageLink, "MyDynamicProperty");
myDynProp.LanguageBranch = "sv"; //Only if you have unique values per languge
myDynProp.PropertyValue.Value = "My Value";
myDynProp.Save();</pre>
<p>You will also find method like ListForPage(PageReference pageLink) that returns a list of all Dynamic Properties for a given page. DO NOT USE that method in when you just want to read a value! Use you PageData class instead for faster access.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fredrikhaglund.se/blog/2008/05/28/access-dynamic-property/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

