Freigeben über


Code sample to aggregate the text from "append changes" column to Multiline text field.

This is a code sample to copy all of the text from the “col1” column to “col2” column. To note again, “col1” is an "append changes" column so the previous edits of the comments field are stored in previous versions of the list item.

    1:  using System;
    2:  using System.Collections.Generic;
    3:  using System.Text;
    4:  using Microsoft.SharePoint;
    5:   
    6:  namespace ConsoleApplication1
    7:  {
    8:      class Program
    9:      {
   10:          static void Main(string[] args)
   11:          {
   12:              SPSite site = new SPSite("https://ms9:101");
   13:              SPWeb web = site.OpenWeb();
   14:              SPList list = web.Lists["list1"];
   15:              string accumulate = "";
   16:              foreach (SPListItem item in list.Items)
   17:              {
   18:                  accumulate = "";
   19:                  foreach (SPListItemVersion ver in item.Versions)
   20:                  {
   21:                      if (ver["col1"] != null)
   22:                          accumulate += ver["col1"].ToString();
   23:                  }
   24:   
   25:                  item["col2"] = accumulate;
   26:                  item.Update();
   27:              }
   28:              web.Dispose();
   29:              site.Dispose();
   30:   
   31:              Console.WriteLine("Done!");
   32:              Console.ReadLine();
   33:          }
   34:      }
   35:  }

image