Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint - get value of calculated field without manual parsing

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

When viewing the list, it might display as: "2 - Big Meeting". When I grab the value from code like so:
myItem["CIDandTitle"]

the value comes back as: "string;#2 - BigMeeting". Is there a "correct" way in sharepoint to extract the value or should i simply split on the semicolon and pound sign?

I am using MOSS2007.

like image 731
Chloraphil Avatar asked May 22 '09 14:05

Chloraphil


1 Answers

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"]);
like image 190
Nathan DeWitt Avatar answered Oct 15 '22 11:10

Nathan DeWitt