Removing '; # 'from SharePoint ListItem data

SharePoint has many pairs of id-value fields that are formatted like this: #value. This is further complicated by fields such as multi-lookup, where retrieving the value of that field can produce results such as id_1; # value_1; # id_2; # value_2; # id_3; # value_3

I am wondering if there is any known built-in function that will simplify this process and at least remove ids from the value.

+1


a source to share


2 answers


Field value objects are stored as strings in the Sharepoint database. For simple values ​​(like "Hello world") this is easy enough. But for complex field values ​​such as an ID / value pair, how to store the entire value as one string is obviously also more difficult. Each field value class in Sharepoint is responsible for its own storage implementation. ToString()

is responsible for writing the string representation of the value; while the field value constructor takes a string and is responsible for parsing it and setting all properties on itself accordingly.

For example, SPFieldUrlValue (which represents <a href="url">description</a>

) has properties Url and Description. Creating a new object SPFieldUrlValue(string fieldValue)

will parse the value and set properties accordingly.



To get a true / correct (and often strongly typed!) Representation of a field's value, you need to know what type the field is and what the class of the field's value is.

+2


a source


The SPField class has many derived classes

For example, if the field type is Lookup (which uses ID; #value), you can check SPField.Type == SPFieldType.Lookup and then throw SPField into SPFieldLookup and use its override methods to get the value of the records.



See Custom Field Value Classes for details .

Also - if I remember correctly (I can't test this right now, so DYOR), you can call .ValueAsText and .ValueAsHtml on the underlying SPField and it will remove the ID; # from values.

+2


a source







All Articles