public static string GetValueFromTextFieldOrFile(this SPListItem item, bool getFromFile, string textfield, string fileField, out bool attached) { attached = false; if (getFromFile) { return(item.GetLookupFileContent(fileField) ?? ""); } else { var res = item[textfield] as string; var content = item.GetAttachmentContent(res); if (content != null) { attached = true; res = content; } return(res); } }