sharepoint 获取所有网站集前40w个文件中启用历史版本文件的大小/数量/最后修改时间

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;

namespace GetVideoFiles
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This tool is designed for find the files that include history vesion in all Site collection.");
           
          
            InitionFile();
            Console.WriteLine("Please input the web url:");
            String weburl = Console.ReadLine();
            Uri webAppUri = new Uri(weburl);
            SPWebApplication webApplication = SPWebApplication.Lookup(webAppUri);

Console.WriteLine("Name\tUpdateTime\tVerNum\tSize\tSizeOfVersions\tTotalSize\tWebUrl");
            writer.WriteLine("Name\tUpdateTime\tVerNum\tSize\tSizeOfVersions\tTotalSize\tWebUrl");

Int64 allSitesSizes = 0;
            Int64 allSitesHistorySizes = 0;
            Int64 allSitesTotalSizes = 0;
           
             foreach (SPSite site in webApplication.Sites)
            {
                DataTable oDtRawData = null;
                oDtRawData = site.StorageManagementInformation(SPSite.StorageManagementInformationType.Document, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 400000);
                /*/// if you wan to see column names, loop through all the columns and find out the names and grab the needed one.
                 foreach (DataColumn oColumn in oDtRawData.Columns)
                         {
                              Console.WriteLine(oColumn.ColumnName);               
                           }
                 */

// SPWeb web = site.OpenWeb();
                                         
                string siteUrl = site.Url;
                Int64 sizes = 0;
                Int64 historySizes = 0;
                Int64 totalSizes = 0;
                Int64 history = 0;
                foreach (DataRow oRow in oDtRawData.Rows)
                {
                
                   // Console.WriteLine("Processing......" + oRow["LeafName"].ToString() + "......" + oRow["WebUrl"].ToString());
                    string historySize2 = oRow["SizeOfVersions"].ToString();
                    history = Convert.ToInt64(historySize2);
                    if (history != 0)
                    {
                        string size1 = oRow["Size"].ToString();
                        string historySize1 = oRow["SizeOfVersions"].ToString();
                        string totalSize1 = oRow["TotalSize"].ToString();
                        Int64 size = Convert.ToInt64(size1);
                        Int64 historySize = Convert.ToInt64(historySize1);
                        Int64 totalSize = Convert.ToInt64(totalSize1);
                        sizes = sizes + size;
                        historySizes = historySizes + historySize;
                        totalSizes = totalSizes + totalSize;

string fullPath = "http://" + webAppUri.Host + "/" + oRow["Directory"].ToString() + "/" + oRow["LeafName"].ToString();
                                           
                        Console.WriteLine(fullPath);
                        SPFile file = null;
                        Int32 verNum = 0;
                        using (SPWeb web = new SPSite(fullPath).OpenWeb())
                        {

file = web.GetFile(fullPath);
                            verNum = file.Versions.Count;
                           //Console.WriteLine(file.Versions.Count + "" + web.Url);
                           //Console.WriteLine(file.TimeLastModified);
                        }

Console.WriteLine(oRow["ModifiedDate"].ToString());
                        // Console.WriteLine(oRow["LeafName"].ToString() + "\t" + oRow["Size"].ToString() + "\t" + oRow["SizeOfVersions"].ToString() + "\t" + oRow["TotalSize"].ToString() + "\t" + oRow["WebUrl"].ToString());
                        writer.WriteLine(oRow["LeafName"].ToString() + "\t"  + oRow["ModifiedDate"].ToString() + "\t"+ verNum + "\t" + oRow["Size"].ToString() + "\t" + oRow["SizeOfVersions"].ToString() + "\t" + oRow["TotalSize"].ToString() + "\t" + oRow["WebUrl"].ToString());
                    }
                    
                }
                if (totalSizes != 0)
                {
                    Console.WriteLine("#SiteSUM\t\t\t{0}MB\t{1}MB\t{2}MB\t{3}", Math.Round(sizes / 1024.0f / 1024.0f, 2), Math.Round(historySizes / 1024.0f / 1024.0f, 2), Math.Round(totalSizes / 1024.0f / 1024.0f, 2), siteUrl);
                    writer.WriteLine("#SiteSUM\t\t\t{0}MB\t{1}MB\t{2}MB\t{3}", Math.Round(sizes / 1024.0f / 1024.0f, 2), Math.Round(historySizes / 1024.0f / 1024.0f, 2), Math.Round(totalSizes / 1024.0f / 1024.0f, 2), siteUrl);

}
                allSitesSizes = allSitesSizes + sizes;
                allSitesHistorySizes = allSitesHistorySizes + historySizes;
                allSitesTotalSizes = allSitesTotalSizes + totalSizes;
               
            }
            Console.WriteLine("#AllSitesSUM\t\t\t{0}MB\t{1}MB\t{2}MB", Math.Round(allSitesSizes / 1024.0f / 1024.0f, 2), Math.Round(allSitesHistorySizes / 1024.0f / 1024.0f, 2), Math.Round(allSitesTotalSizes / 1024.0f / 1024.0f, 2));
            writer.WriteLine("#AllSitesSUM\t\t\t{0}MB\t{1}MB\t{2}MB", Math.Round(allSitesSizes / 1024.0f / 1024.0f, 2), Math.Round(allSitesHistorySizes / 1024.0f / 1024.0f, 2), Math.Round(allSitesTotalSizes / 1024.0f / 1024.0f, 2));

CloseFile();
            //Console.ReadKey();

}

static StreamWriter writer;
        static void InitionFile()
        {
            writer = new StreamWriter("files.txt", false);
        }
        static void CloseFile()
        {
            writer.Flush();
            writer.Close();
        }

static void WriteLine(string msg)
        {
            writer.WriteLine(msg);
        }
    }
}

时间: 2024-08-10 21:19:50

sharepoint 获取所有网站集前40w个文件中启用历史版本文件的大小/数量/最后修改时间的相关文章

SharePoint 2013跨网站集发布功能简介

在SharePoint Server 2013网站实施中,我们经常会遇到跨网站集获取数据,而2013的这一跨网站集发布功能,正好满足我们这样的需求. 使用SharePoint 2013中的跨网站发布,我们可以使用列表和其他库来存储在发布网站上重复使用的内容,通过内容搜索部件来读取配置的跨网站集信息,下面,让我们通过一个简单的例子,了解一下这一功能吧! 1.使用SharePoint 2013跨网站集发布功能,首先需要在源网站和目标网站开启Cross-Site Collection Publishi

SharePoint 2013 新建网站集图解

原文:SharePoint 2013 新建网站集图解 前言:接触SharePoint的人可能是越来越多,但是很多人一接触就很迷茫,在技术群里问如何新建网站集,这样一篇图解,帮助新手学习在搭建好SharePoint环境之后,如何创建一个网站集,做一个基本的参考,希望能够给相关的人带来帮助. 步骤:新建Web应用程序,使用创建的Web应用程序创建网站集,添加备用访问映射. 一.打开管理中心,点击管理Web应用程序: 二.点击新建按钮: 三.先填写端口号(先填写端口号,上面的名称会自动跟着端口号改变,

SharePoint Online 设置网站集

前言 本文介绍如何在Office 365中设置SharePoint Online网站集,当我们创建好SharePoint Online站点,开始使用之前,一定会有一些基本的设置,本文就为大家介绍这些基本的设置. 正文 通过登录地址登录到Office 365环境中的SharePoint Online站点,我们可以在右上角的设置按钮中进入网站设置: 登录地址:https://linyus.sharepoint.com/sites/ELearning/ 本文,我们会介绍一些基本的设置,其中,最常用的就

SharePoint PowerShell 清空网站集回收站

故事 在很久很久以前,碰到过一次这样的需求,给客户做好的站点经过层层测试,需求变更在测试,历经半年时间终于要上线了. 然而,有个问题是,回收站里的东西太多太多了,作为开发人员,尤其是有强迫症的开发人员,势必要清空回收站. 那么,问题就来了,大大小小的子网站几十个,回收站里的东西全都清除一遍,没有个半天时间可能都干不完. 作为一个热(xi)爱(huan)技(tou)术(lan)的程序猿,想的是有怎样快捷的方式,让程序帮助我们完成这项任务呢? 解决方法 #Get SPSite $Site = Get

sharepoint 2013创建网站集,域帐户无法访问,只有administrator可以访问

解决方法: 1.创建WEB应用程序时,可配置帐户必须为域帐户 2.确定关闭防火墙(这是重点) 我在测试时发现80端口和30714端口在其它同事的电脑上(域帐户)都可以访问,除这两个端口以后都无法访问,出现以下错误,就是因为防火墙没关闭问题

SharePoint 使用PowerShell恢复误删的网站集

//来源:http://www.cnblogs.com/jianyus/p/3666047.html 在SharePoint网站集的使用中,我们很有可能会误删我们需要的网站集,SharePoint其实并没有把网站集删掉,只是放到了SPDeletedSite中,这样,我们还可以通过PowerShell找回来我们误删的网站集,具体操作详见下面介绍. 1.获取已经从管理中心删除的网站集 Get-SPDeletedSite /sites/11 2.如果有两个被删除的网站集,可以根据Site Id和删除时

sharepoint 创建网站集出错

删除顶级网站集后,又新建网站集报错:名为"SharePoint - 80"的父级 Microsoft.SharePoint.Administration.SPWebApplication 下已存在名为"a04d7106-70c3-4ac4-9d2a-45692032ec62"的 Microsoft.SharePoint.Publishing.Internal.UnpublishJobDefinition 类型的对象.请重命名您的对象,或删除现有对象. 1.确认web

Sharepoint 2013 网站集的删除与还原

一.可以通过三种方法删除网站集: 1.打开Sharepoint 2013 管理页面首页 ---> 单击‘应用程序管理(Application Management)’并进入该页面 ---> 单击‘删除一个网站集(Delete a site collection)’并打开该页面 ---> 选择想要删除的网站集并点击右下角的‘删除’按钮 ---> 完成删除. 2.打开想要删除的网站集的首要网站 ---> 点击页面右上角的齿轮按钮 ---> 在下拉菜单中选择‘网站设置(Sit

sharepoint 2013 使用powershell更改网站集配额和锁定

打开sharepoint powershell 2013,使用管理员方式打开 逐行输入以下命令: $Admin =  new-object Microsoft.SharePoint.Administration.SPSiteAdministration('http://10.0.0.52:2014') $Admin.ClearMaintenanceMode() $site.MaintenanceMode sharepoint 2013 使用powershell更改网站集配额和锁定,布布扣,bub