Sharepoint sets the number of historical versions for a document library C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.