Try this:
((EPiServer.SpecializedProperties.PropertyXhtmlString)CurrentPage.Property["MyProperty"]).ToWebString()
Ugly first draft of something that seems to fix my problem...
private string GetDescription(PageData page)
{
string r = String.Empty;
if (page["MainBody"] != null)
{
var prop = new EPiServer.Web.WebControls.Property();
prop.PageLink = page.PageLink;
prop.PropertyName = "MainBody";
this.Page.Controls.Add(prop);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
prop.RenderControl(htw);
r = sw.GetStringBuilder().ToString();
prop.Visible = false;
}
Think its better to add the control like this
Placeholder content=new Placeholder();
this.Controls.Add(content);
PropertyData MyProp=CurrentPage["MainBody"];
IPropertyControl result = PropertyControlClassFactory.Instance.CreatePropertyControl(MyProp);
(result as Control).ID = MyProp.Name;
content.Controls.Add((result as Control));
result.PropertyData = MyProp;
result.Properties = page.Property;
result.RenderType = RenderType.Default;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
content.Render(htw);
content.Visible=false:
return sw.GetStringBuilder().ToString();
The EPiServer.Property control have a lot of overhead. and with my method you can add it as a part of property function. WebControls.Property have a lot of code, and its easy too loose control of whats going on there:)
One example of how the Property webcontrol can be misused is in the example. The "correct" way of use it would be to
var prop = new EPiServer.Web.WebControls.Property();
prop.InnerProperty=page.Property["MainBody"]
and not the PropertyName and PageLink variant. since that will get the page from the pagelink, and may not be the actully property you are looking at.
The code inside WebControls.Property have private fields for the currentPage so you cant override the currentpage either.
Here's a solution that worked for me: http://tednyberg.com/post/Parse-EPiServer-XHTML-property-with-Dynamic-Content.aspx