0

I'm trying to iterate over list item versions, to get any change in versions, but unfortunately I always get the same current version data, unless the VersionLabel.

  if(versions.Count > 0 && termes.EnableVersioning)
  {
     for (int index = 0 ; index < versions.Count ; index++)
     {

        string var1 = versions[index].VersionLabel;

        string  var2 =       
              versions[index].ListItem["fieldiinternalnamename1"];

        string var3 = 
             versions[index].ListItem["fieldiinternalnamename2"];

        string var4 = 
             versions[index].ListItem["fieldiinternalnamename3"];


         }
     }

my complete code is:

 if(versions.Count > 0 && termes.EnableVersioning)
 {
     for (int index = 0 ; index < versions.Count ; index++)
     {

         //second tabe for version titles
         table = new PdfPTable(6);
         table.TotalWidth = 520f;
         table.LockedWidth = true;

         table.HorizontalAlignment = 0;
         table.DefaultCell.Border = 0;

         bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, 
         BaseFont.CP1252, false);
         font = new Font(bfTimes, 7, Font.NORMAL, BaseColor.BLACK);

         //modifier
         cell = new PdfPCell(new Phrase(versions[index].VersionLabel, 
          font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

         cell.Border = 0;

         table.AddCell(cell);
         //modifier
         cell = new PdfPCell(new  

    Phrase(versions[index].ListItem
    [ConstVariables2.Terme_Modifier_par2_encodé] != null ?   
     versions[index].ListItem
   [ConstVariables2.Terme_Modifier_par2_encodé].ToString().Trim()
   .Split(new string[] { "#" }, StringSplitOptions.None)[1] : "", font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

         cell.Border = 0;

         table.AddCell(cell);

         //title
         cell = new PdfPCell(new Phrase(versions[index].ListItem.Title, 
         font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

         cell.Border = 0;

         table.AddCell(cell);

         //english
         cell = new PdfPCell(new Phrase(versions[index].ListItem
         [ConstVariables2.Terme_Anglais2_encodé] != null ?   
          versions[index].ListItem
         [ConstVariables2.Terme_Anglais2_encodé].ToString().Trim() : "", 
          font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

         cell.Border = 0;

         table.AddCell(cell);

         //french
         cell = new PdfPCell(new Phrase(versions[index].ListItem
        [ConstVariables2.Terme_Francais2_encodé] != null ? 
         versions[index].ListItem
        [ConstVariables2.Terme_Francais2_encodé].ToString().Trim() : "", 
        font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

            cell.Border = 0;

           table.AddCell(cell);

         //deutsch
         cell = new PdfPCell(new Phrase(versions[index].ListItem
        [ConstVariables2.Terme_Allemand2_encodé] != null ? 
        versions[index].ListItem
        [ConstVariables2.Terme_Allemand2_encodé].ToString().Trim() : "", 
          font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;

         cell.Border = 0;

            table.AddCell(cell);

         //arabic
         bfTimes = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, 
         BaseFont.EMBEDDED);
           font = new Font(bfTimes, 9, Font.NORMAL, BaseColor.BLACK);

         cell = new PdfPCell(new Phrase(versions[index].ListItem
         [ConstVariables2.Terme_Arabe2_encodé] != null ? 
          versions[index].ListItem
         [ConstVariables2.Terme_Arabe2_encodé].ToString().Trim() : "", 
         font));
         cell.PaddingLeft = 0;
         cell.PaddingRight = 0;
         cell.HorizontalAlignment = Element.ALIGN_LEFT;
         //cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;

         cell.Border = 0;

         table.AddCell(cell);

         table.WriteSelectedRows(0, -1, doc.Left, height, 
         writer.DirectContent);


      }
   }

2 Answers 2

0

You code is not correct. You can overwriting the variables.

Try below

if(versions.Count > 0 && termes.EnableVersioning)
{
    List<string> var1 = new List<string>();
    List<string> var2 = new List<string>();
    List<string> var3 = new List<string>();
    List<string> var4 = new List<string>();
    for (int index = 0 ; index < versions.Count ; index++)
    {
        var1.Add(versions[index].VersionLabel);
        var2.Add(versions[index].ListItem["fieldiinternalnamename1"].ToString());
        var3.Add(versions[index].ListItem["fieldiinternalnamename2"].ToString());
        var4.Add(versions[index].ListItem["fieldiinternalnamename3"].ToString());
    }

    //HERE Iterate through the list
}
2
  • thanks mr hashim why is not correct because i'm trying to iterate on versions and display each iiteration (or version) on table row to be printed in pdf file
    – ezzaam
    Commented Apr 22, 2015 at 14:47
  • There was no code to do tat. so i assumed.. please post complete code Commented Apr 22, 2015 at 14:49
0

the correct response is ; use the internalname to the version object directly :

 if(versions.Count > 0 && termes.EnableVersioning)
 {
   for (int index = 0 ; index < versions.Count ; index++)
   {

    string var1 = versions[index].VersionLabel;

    string  var2 =       
          versions[index]["fieldiinternalnamename1"];

    string var3 = 
         versions[index]["fieldiinternalnamename2"];

    string var4 = 
         versions[index]["fieldiinternalnamename3"];


     }
 }

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.