Wednesday, March 4, 2015

Copy/Fetch Multi line field-Append changes to Existing Text to Another field


Copy/Fetch Multi line field-Append changes to Existing Text to Another file.



// string key= Field data which your capturing

static void Main(string[] args)



{
 
SPSecurity.RunWithElevatedPrivileges(delegate()



{
 
using (SPSite site = new SPSite("SiteUrl"))



{
 
using (SPWeb web = site.OpenWeb())



{
 
SPList list = web.Lists.TryGetList("TestRKU");

if (list != null)



{
 
SPListItemCollection itemColl = list.Items;

foreach (SPListItem item in itemColl)



{
 
GetVersionedMultiLineTextAsPlainText(item, "MultiSource");





}

}

}

}

});

}
 
public static void GetVersionedMultiLineTextAsPlainText(SPListItem item, string key)



{
 
StringBuilder sb = new StringBuilder();

foreach (SPListItemVersion version in item.Web.Lists[item.ParentList.ID].Items[item.UniqueId].Versions)



{
 
SPFieldMultiLineText field = version.Fields[key] as SPFieldMultiLineText;

if (field != null)



{
 
string comment = field.GetFieldValueAsText(version[key]);

if (comment != null && comment.Trim() != string.Empty)



{
 
sb.Append("");

sb.Append(version.CreatedBy.User.Name).Append(" (");

sb.Append(version.Created.ToString("MM/dd/yyyy hh:mm tt"));

sb.Append(") ");



sb.Append(comment);

}

}

}
 
item["Destination"] = sb.ToString();



item.SystemUpdate();

}
 

No comments:

Post a Comment