SharePoint - get value of calculated field without manual parsing

前端 未结 2 1676
一向
一向 2020-12-17 19:56

I have a calculated field in a list with this formula:
=CID & \" - \" & Title

When viewing the list, it might display as: \"2 - Big Meeting\

相关标签:
2条回答
  • 2020-12-17 20:20

    The answer given by @Nathan does not specify that you need to provide the display name of the field. It wont work with internalName. Moreover, I'm likely to use as to cast the result.

    var cf = list.Fields["calculatedfieldDisplayName"] as  SPFieldCalculated;
    String value = cf.GetFieldValueAsText(item["calculatedfieldDisplayName"]);
    
    0 讨论(0)
  • 2020-12-17 20:25

    You have to cast it to an SPCalculatedField:

    SPFieldCalculated cf = (SPFieldCalculated)myItem.Fields["CIDandTitle"];
    string value = cf.GetFieldValueForEdit(myItem["CIDandTitle"]);
    

    or

    string value = cf.GetFieldValueAsText(myItem["CIDandTitle"]);
    
    0 讨论(0)
提交回复
热议问题