SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When running my SPSiteDataQuery (code below), I appear to be getting 1;# before the actual Author Name. Can anyone point me in the right direction towards an explanation to this please?

   SPSiteDataQuery query = new SPSiteDataQuery();

   query.Lists = @"<Lists ServerTemplate='850' Hidden='TRUE' />";
   query.ViewFields = @"<FieldRef Name=""Title"" /><FieldRef Name=""Author"" />";
   query.Webs = @"<Webs Scope='SiteCollection'/>";
   query.Query = @"<Where>
                       <FieldRef Name='ContentTypeId'/>
                       <Value Type='Text'>[LONG GUID]</Value>
   query.RowLimit = 10;

   DataTable dt = web.GetSiteData(query);

So in every dt I'll have: "1;#Daniel McNulty" in the Author column for example.

share|improve this question
up vote 1 down vote accepted

When you query the content you are going to get it back in its actual format. For some fields like lookup fields and user fields the data type is actually multi-part and will use a format like this. If you are looking for the just the display name, just format the value the way you want it.

share|improve this answer
Thanks Mike. I don't have a problem substring'ing it, I just wanted to make sure there wasn't a more relevant field (somehow) with just the display name or that I wasn't being inefficient in any way. This is fine. Thanks. – JᴀʏMᴇᴇ Jun 18 '12 at 15:42
Small point, make sure to parse it to characters after the #, as the ID (1 in this case) can be much greater than 9 and thus can take up a variable amount of characters. – Zork Jun 18 '12 at 15:44
Thanks a lot Zork, noted. – JᴀʏMᴇᴇ Jun 18 '12 at 15:46

Author column uses an SPFieldLookup to the User Information List.

SharePoint 2007 and 2010 often use ;# as an internal splitter on their Data fields. SPSiteDataQuery returns the internal data values, Generally if you find a ;# there will be a built in Class that handles the conversion for you.

You can use the SPFieldLookupValue Class to handle the relevant string split.

string authorField = item["Author"].ToString();
SPFieldLookupValue authorValue = new SPFieldLookupValue(authorField);

// The account Login Name of the author 
// The User Information List ID of the user

Depending on what you are trying to do the ID can be more useful than the Login Name.

For rendering the Datatable in a SPDataGrid you can use Item Templates to transform the values to a more useful format, E.G. A Link to the users profile.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.