3

Does anyone know the solution for this?

If I'm querying items by SPSiteDataQuery I receive a DataTable with DataRow objects.

I could fetch the current version of an item and check if it ends with ".0" (indicating a major version).

If it isn't a major version, I could convert the DataRow to SPListItem and get the last published major version as SPListItem.

Else (if it is a major version) i can proceed with my DataRow object:

DataTable results = ...//get results from SPSiteDataQuery

foreach (DataRow row in results.Rows){

 string version = (string)row["_UIVersionString"];

 if (!version.EndsWith("0"))
 {
    string absUrl = (string)row["EncodedAbsUrl"];
    SPListItem item = web.GetFile(absUrl).Item;
    SPListItem newestItem = null;

    foreach (SPListItem publishedMajorVersionItem in item.Versions)
    {
      if (publishedMajorVersionItem.Level == SPFileLevel.Published)
        newestItem = publishedMajorVersionItem;
    }
 }

 //proceed with DataRow object
 CustomObject o = new CustomObject();
 o.Title = (string)row["Title"];
}

What is missing is: how can I get a DataRow object from the SPListItem?

Or: is there another way to get the last major published version if I'm using SPSiteDataQuery without converting the DataRow to SPListItem?

1 Answer 1

1

You cannot, but since you already have your item in hand you can update your current row with latest item data. Something like:

foreach (DataColumn column in results.Columns)
{
    SPField field = newestItem.Fields.TryGetFieldByStaticName(column.ColumnName);
    if (field != null)
    {
        row[field.InternalName] = newestItem[field.InternalName];
    }
 }
 row.AcceptChanges();

Please note I didn't test this code. I am just providing it as example.

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.