Anders Hattestad
Oct 16, 2008
  13120
(1 votes)

Dynamic content and State attribute

I had a problem with the State attribute. This is the attribute that is saved inside the span [SPAN class=dynamiccontent contentEditable=false style="....." disabled hash="oqAE..zt1Y=" state="xxx"][/SPAN]

I tried to save some xml inside it, and the dynamic content render just wouldnt save. it seems like the attribute can contains html/xml tags.

The trick was to convert my string into Base64.

public string Value;
#region Value64
public string Value64
{
    get
    {
        if (Value == null)
            return null;
        return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes((string)Value));

    }
    set
    {
        if (value != null)
        {
            
            byte[] toDecodeByte = Convert.FromBase64String(value);

            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();

            int charCount = utf8Decode.GetCharCount(toDecodeByte, 0, toDecodeByte.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(toDecodeByte, 0, toDecodeByte.Length, decodedChar, 0);
            string result = new String(decodedChar);
            Value = result;

        }
    }
}
#endregion
#region State (64)
public string State
{
    get
    {
            return Value64;
    }
    set
    {
        Value64 = value;
        
    }
}
#endregion
Oct 16, 2008

Comments

Sep 21, 2010 10:32 AM

Good post Anders. Because the state string is stored as part of the XHTML Property it cannot contain XML in raw form. In these cases we recommend Binary Serialization as you have used. Paul EPiServer Dev Team
/ Paul Smith

Sep 21, 2010 10:32 AM

Thx, but couldn't the function that retrives the State string convert it for us?
/ Anders Hattestad (hattestad@gazette.no)

Please login to comment.
Latest blogs
Vulnerability in EPiServer.GoogleAnalytics v3 and v4

Introduction A potential security vulnerability was detected for Optimizely Google Analytics addon (including EPiServer.GoogleAnalytics and...

Bien Nguyen | Sep 20, 2023

Overriding Optimizely’s Content Recommendations Block to Implement Custom Recommendations

Introduction The Content Recommendations add-on for Optimizely CMS dynamically recommends content from your site tailored to the interests of each...

abritt | Sep 13, 2023 | Syndicated blog

Developer contest! Install the AI Assistant and Win Bose QC45 Headphones!

We are thrilled to announce a developer contest where you have the chance to win a pair of Bose Headphones. The goal is to be the first developer t...

Luc Gosso (MVP) | Sep 7, 2023 | Syndicated blog

Send Optimizely notifications with SendGrid API, not SMTP

If your Optimizely site already sends transaction emails through an email platform API, why not do the same with Optimizely notification emails?

Stefan Holm Olsen | Sep 6, 2023 | Syndicated blog