views:

230

answers:

2

Can a SharePoint expert explain to me the ;# in data returned by the GetListItems() call to the Lists web service?

I think I understand what they are doing here. The ;# is almost like a syntax for making a comment... or better yet, including the actual data (string) and not just the ID. This way you can use either, but they are nicely paired together in the same column.

Am I way off base? I just can't figure out the slighly different use. For example

I have a list with:    
ows_Author  
658;#Tyndall, Bruno    
*in this case the 658 seems to be an ID for me in a users table somewhere*

ows_CreatedDate (note: a custom field. not ows_Created)    
571;#2009-08-31 23:41:58    
*in this case the 571 seems to be an ID of the row I'm already in. Why the repetition?*   

Can anyone out there shed some light on this aspect of SharePoint?

+8  A: 

The string ;# is used as a delimiter by SharePoint's lookup fields, including user fields. When working with the object model, you can use SPFieldLookupValue and SPFieldUserValue to convert the delimited string into a strongly-typed object. When working with the web services, however, I believe you'll need to parse the string yourself.

You are correct that the first part is an integer ID: ID in the site user list, or ID of the corresponding item in the lookup list. The second part is the user name or value of the lookup column.


Nicolas correctly notes that this delimiter is also used for other composite field values, including...

  • SPFieldLookupValueCollection
  • SPFieldMultiColumnValue
  • SPFieldMultiChoiceValue
  • SPFieldUserValueCollection
dahlbyk
This notation is also useful when a field stores more than one item (in a multi-select field for example)
Nicolas Irisarri
+2  A: 

The SPFieldUser inherits from the SPFieldLookup which uses the ;# notation. You can easily parse the value by creating a new instance of the SPFieldLookupValue class:

string rawValue = "1;#value";
SPFieldLookupValue lookupValue = new SPFieldLookupValue(rawValue);
string value = lookupValue.LookupValue; // returns value
Waldek Mastykarz - MOSS MVP