field name in c# does not match the view or list name in browser ?


  • When I look at a view or list in a browser  , the column name is 'Project #'

    when I read the same data in c# (a collection of FieldValues in a ListItem)  using c# (Microsoft sharepoint client 2013), I see something like

    Project_x0020__x0023_ .

    in c# , how can I access the view column names?





    • Edited by peter clift Friday, July 19, 2013 6:15 PM better
    Friday, July 19, 2013 6:08 PM


All replies

  • Hi Peter,

    I am not sure whether I understood your exact requirement. The following code snippets should help you. If you need anything else, please let us know.

    1) To read the list of fields/columns in a view, use the following code -

    SPList list = web.Lists["Tools"]; SPView listView = web.Lists["Tools"].Views["All Items"]; SPViewFieldCollection viewfieldCollection = listView.ViewFields; foreach (string viewFieldName in viewfieldCollection) { SPField columnDetails = list.Fields[viewFieldName];


    2) Get column/field display name from field instance -> SPField.Title

    3) Get field (from web/list - same way)

    Using Field Internal name -  web.Fields.GetField(Display name or internal name)

    Using Field display name - web.Fields[Display Name]

    4) Access list item value using display name of the field - 

    item[Field display name] - Return object

    Also, to get the internal column name of a list field, simply goto List settings - click on desired column and see the Field name in URL.

    Hope it helps..


    Saturday, July 20, 2013 9:58 AM
  • In your column Project_x0020__x0023_ ,_x0020 is space and _x0023 will another special character..

    With the help of below method,you are able to read it.

    Sunday, July 21, 2013 4:44 PM
  • @Peter, Added to the above post, there are few more approaches you can follow 

    You can use CSOM(C#) to get your column details in the list 

    Or using webservice in C#

    My Blog-| Twitter
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful

    • Marked as answer by peter clift Monday, July 22, 2013 4:30 PM
    Sunday, July 21, 2013 10:59 PM
  • That answers my question! I need to use field.title instead of field.InternalName

    regards ,Peter 

    • Marked as answer by peter clift Monday, July 22, 2013 4:28 PM
    • Unmarked as answer by peter clift Monday, July 22, 2013 4:28 PM
    • Edited by peter clift Monday, July 22, 2013 4:30 PM good
    Monday, July 22, 2013 4:19 PM