Sharepoint 为文档库设置历史版本数 c#
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sharepoint 为文档库设置历史版本数 c#相关的知识,希望对你有一定的参考价值。
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:"); //对当前历史版本数设置超过多少的文档库进行重置
String getVerNumString = Console.ReadLine();
Int16 getVerNum = Convert.ToInt16(getVerNumString);
Console.WriteLine("Please input Version num which will be used:");//输入重新设置文档库的历史版本值
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);
}
}
}
本文出自 “博深” 博客,转载请与作者联系!
以上是关于Sharepoint 为文档库设置历史版本数 c#的主要内容,如果未能解决你的问题,请参考以下文章
Sharepoint 2010/2013 文档库 - 文档版本控制
如何设置文档库的权限以启用文件-> 仅在 sharepoint 2013 中的新选项