Enable SharePoint List versioning using c#:
using (SPSite spsite = new SPSite("http://contoso.com"))
{
SPWeb spweb = spsite.OpenWeb();
SPList list = spweb.Lists["ListName"];
list.EnableVersioning = true;
list.Update();
}
Retrieve SPListItem versions using c#:
public class PageVersions
{
public string PageVersion { get; set; }
public SPUser PageVersionOwner { get; set; }
public DateTime PageVersionDate { get; set; }
}
public class GetVersionsClass
{
public PageVersions CalculateVersionPoints(SPListItem item,int prevDates)
{
PageVersions pv = new PageVersions();
SPListItemVersionCollection oVersionInfo = item.Versions;
foreach (SPListItemVersion oVersion in oVersionInfo)
{
if (oVersion.Level == SPFileLevel.Published)
{
if (oVersion.Created.ToLocalTime().CompareTo(DateTime.Now.AddDays(prevDates)) >= 0)
{
pv.PageVersion = oVersion.VersionId.ToString();
pv.PageVersionDate = oVersion.Created;
pv.PageVersionOwner = oVersion.CreatedBy.User;
}
}
}
return pv;
}
}
No comments:
Post a Comment