visual-studio-2010sharepoint-2010spquerydocument-set

SPQuery sorting issue


I have this SPListItem.Folder in sharepoint that contains a property named "Asset ID".

I have this data in my list

Asset ID  |     Name      |  Asset Type 
    1     |  GamesFolder  |    Games
    2     |  AppsFolder   |    softwares
    3     |  MusicFolder  |    music

In my code I did this

SPList objList = web.Lists["MyList"];
SPQuery query = new SPQuery();

query.Query = "<OrderBy><FieldRef Name='Asset ID' Ascending='FALSE'/></OrderBy>";
query.ViewAttributes = "Scope=\"Recursive\"";               
query.RowLimit = 1;

SPListItemCollection items = objList.GetItems(query);

return objList.Items[0].Folder.Properties["Asset ID"].ToString();

I use .Folder because every entry in the list is a DocumentSet. The returned value is always "1". I don't know what's wrong why my sorting doesn't work at all.

Please help me resolve this issue. Thanks.


Solution

  • Hi Carls I think there is issue for field name. U include space in field name

    If you want to avoid having to seek out what the internal name of a particular field is, when you first name your column, do not include any spaces or special characters. Once the field (column) has been created, go back and rename the field to include the spaces or special characters as desired. SharePoint will still retain the original field name without spaces and you can use that directly in your query without issue.