Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using Microsoft.SharePoint;
Using Microsoft.SharePoint.Administration;
Using System.IO;
Using System.Web;
Using System.Text.RegularExpressions;
Using System.Data;
Using System.Collections;
Namespace Resetonewebdocumentslibraryversionnum
{
Class Program
{
static void Main (string[] args)
{
string[] temp = System.IO.File.ReadAllLines ("Path.txt", System.Text.Encoding.UTF8);
System.Text.Encoding.GetEncoding ("Unicode"));
Initionfile ();
Console.WriteLine ("Please input Version num which had been set:"); Resets a document library that has more than the current number of historical versions set
String getvernumstring = Console.ReadLine ();
Int16 getvernum = convert.toint16 (getvernumstring);
Console.WriteLine ("Please input version num which'll be used:");//Enter the historical version value of the document library to reset
String resetvernumstring = Console.ReadLine ();
Int16 resetvernum = convert.toint16 (resetvernumstring);
Uri Webappuri = new Uri (Weburl);
Spwebapplication WebApplication = Spwebapplication.lookup (Webappuri);
Console.WriteLine ("Weburl\tdocumenturl\tdocumentlibrary\tmajorversionlimit\tminorversionslimit");
Writer. WriteLine ("Weburl\tdocumenturl\tdocumentlibrary\tmajorversionlimit\tminorversionslimit");
foreach (string weburl in temp)
{
using (SPSite site = new SPSite (Weburl))
{
using (SPWeb Web = site. OpenWeb ())
{
foreach (SPList list in Web. Lists)
{
if (list. enableversioning.tostring () = = "True" && list. basetemplate.tostring () = = "DocumentLibrary" && list. Hidden.tostring ()! = "True" && list. enableversioning.tostring () = = "True" && list. Title! = "Site Collection Documents" && list. Title! = "Site Collection Images" && list. Title! = "Style Library")
{
if (list. Majorversionlimit = = 0 | | List. Majorversionlimit >= Getvernum | | List. Majorwithminorversionslimit >= Getvernum)
{
if (list. Majorversionlimit >= getvernum) list. Majorversionlimit = 20;
if (list. Enableminorversions.tostring ()! = "False" && list. Majorwithminorversionslimit >= getvernum) list. Majorwithminorversionslimit = Resetvernum;
List. Update ();
Console.WriteLine (list. Title + "\ T" + list. Majorversionlimit + "\ T" + list. Majorwithminorversionslimit);
Writer. WriteLine (list. Parentweburl.tostring () + "\ T" + list. Defaultviewurl + "\ T" + list. Title + "\ T" + list. Majorversionlimit + "\ T" + list. Majorwithminorversionslimit);
}
}
}
}
}
}
CloseFile ();
Console.readkey ();
}
Static StreamWriter writer;
static void Initionfile ()
{
writer = new StreamWriter ("HistoryVer.txt", true);
}
static void CloseFile ()
{
Writer. Flush ();
Writer. Close ();
}
static void WriteLine (String msg)
{
Writer. WriteLine (msg);
}
}
}
This article from "Bo shen" blog, reproduced please contact the author!
Sharepoint sets the number of historical versions for a document library C #