1

For JSOM we have a great method called get_fieldValuesAsText that returns formatted field value. The same value as user can see it in the list. I am really supprised that I can't find anything like this on the native Sharepoint object model! Am I missing something?

1

SharePoint object model also has a nifty way of getting all the values. GetDataTable method returns a data table with all the field values.

Update:

To return all fields as string, you can clone the DataTable and get string values in another DataTable.

DataTable dt = list.GetItems(new SPQuery()).GetDataTable();
DataTable dtClone = dt.Clone(); //just copy structure, no data
for (int i = 0; i < dtClone.Columns.Count; i++)
{
if (dtClone.Columns[i].DataType != typeof(string))
    dtClone.Columns[i].DataType = typeof(string);
}
foreach (DataRow dr in dt.Rows)
{
dtClone.ImportRow(dr);
}
  • itemRow["Modified"] still returns DateTime object – Serhiy Aug 9 '15 at 9:33
  • @Serhiy modified code. Please check if it suits your requirement. – Akhoy Aug 10 '15 at 6:19
  • cant you get the values using item["FieldName"] and then convert it as per your need, as far as I know there isn't any such method as you stated in the question. – Vishwas Goswami Aug 10 '15 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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