码迷,mamicode.com
首页 > Windows程序 > 详细

Sharepoint 为文档库设置历史版本数 c#

时间:2017-03-23 22:50:34      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:sharepoint

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

原文地址:http://pclzr.blog.51cto.com/30415/1909734

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!