sharepoint - Detect a change in a rich text field's value in SPItemEventReceiver? -
i have event receiver attached custom list. current requirement implement column level security rich text field (multiple lines of text enhanced rich text).
according post, can field's before , after values so:
object obefore = properties.listitem[f.internalname]; object oafter = properties.afterproperties[f.internalname];
the problem i'm running issues comparing these 2 values, lead false positives (code detecting change when there wasn't one).
exhibit a: using tostring on both objects
obefore.tostring()
<div class=externalclass271e860c95ff42c6902be21043f01572> <p class=msonormal style="margin:0in 0in 0pt">text. </div>
oafter.tostring()
<div class=externalclass271e860c95ff42c6902be21043f01572> <p class=msonormal style="margin: 0in 0in 0pt">text. </div>
problems?
- html tags capitalized
- random spaces (see additional space after
margin:
)
using getfieldvalueforedit or getfieldvalueashtml seem result in same values.
"ok," say, lets compare plain text values.
exhibit b: using getfieldvalueastext
fortunately, method strips of html tags out of value , plain text displayed. however, using method led me discover additional issues whitespace characters:
in before value:
- sometimes there additional newline characters.
- sometimes spaces displayed non-breaking spaces (ascii char code 160)
question:
how can detect if user changed rich text field in event receiver?
- [ideal] detect change html or text or white space
- [acceptable] detect changes text or white space
- [not good] detect changes text characters (strip non-alphanumeric characters)
what happens if set listitem field new value , read out? give same formatting?
object obefore = properties.listitem[f.internalname]; properties.listitem[f.internalname] = properties.afterproperties[f.internalname] object oafter = properties.listitem[f.internalname]; //dont update properties.listitem[f.internalname] = obefore;
Comments
Post a Comment