0

I programmatically created a library "DropDownLibrary" with some field "ReviewType"(text), "SubmittedDate"(datetime), "Created"(the sharepoint field)... and it works in the browser, I can insert new document and set field value. But when I want to bind my listview with some fields , I put the list content in dataTable but SubmittedDate is empty in result: with this message : "SubmittedDate does not belong to table DropDownLibrary"

     SPQuery objQuery = new SPQuery();    
    objQuery.ViewFields = string.Format(DROPDOWNLIBRARY_FIELDS, "AGENTID_FIELD","ID_FIELD", "CREATED_FIELD","SALES_FIELD", "SUBMITTEDDATE_FIELD"); ...
      DataTable fSDataTable = List.GetItems(objQuery).GetDataTable())
      var result = from fSDataTables in fSDataTable .AsEnumerable()
 select new {
 SubmittedDate = DataUtilities.GetSafeString(fSDataTables["SubmittedDate"])
  };

PS :When I try with "Created" it works,

var result = from fSDataTables in fSDataTable .AsEnumerable()
     select new {
     Created= DataUtilities.GetSafeString(fSDataTables["Created"])
      };

Any ideas ? thanks

2
  • Did you get it working? have you tried below solution?
    – Hardik
    Commented Jul 4, 2016 at 5:45
  • Is it working for you? Kindly post the resolution.
    – Hardik
    Commented Jul 14, 2016 at 5:38

1 Answer 1

0

You need to change these lines

SPQuery objQuery = new SPQuery();    
objQuery.ViewFields = string.Format(DROPDOWNLIBRARY_FIELDS, "AGENTID_FIELD","ID_FIELD", "CREATED_FIELD","SALES_FIELD", "SUBMITTEDDATE_FIELD"); ...
  DataTable fSDataTable = List.GetItems(objQuery).GetDataTable();

With below code

SPQuery query = new SPQuery();
string[] viewFields = new string[5] { "DROPDOWNLIBRARY_FIELDS", "AGENTID_FIELD","ID_FIELD", "CREATED_FIELD","SALES_FIELD", "SUBMITTEDDATE_FIELD" };
query.Query = queryString;

  string queryViewFields = string.Empty;
  foreach (string viewField in viewFields)
  {
    string field = web.Fields[viewField];
    string queryViewField = string.Format("<FieldRef Name='{0}' />", field.InternalName);

    queryViewFields += queryViewField;
  }

  // To me, this queryViewFields also seems to be fine
query.ViewFields = queryViewFields;
DataTable fSDataTable = List.GetItems(objQuery).GetDataTable()

You will get all the results.

3
  • Did you tried it? Is it working for you? If not than please let me know so i can help you further.
    – Hardik
    Commented Jun 30, 2016 at 13:43
  • in : private const string DROPDOWNLIBRARY_FIELDS = "<FieldRef Name='{0}' /><FieldRef Name='{1}' /><FieldRef Name='{2}' /><FieldRef Name='{3}' /><FieldRef Name='{4}' /><FieldRef Name='{5}' /><FieldRef Name='{6}' /><FieldRef Name='{7}' /><FieldRef Name='{8}' /><FieldRef Name='{9}' /><FieldRef Name='{10}' />"; I was missing the last one {10}, so it brings 10 fields instead of 11 (SubmittedDate).
    – BKChedlia
    Commented Jul 15, 2016 at 8:13
  • You need to check for all columns.
    – Hardik
    Commented Jul 15, 2016 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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