sharepoint 統計所有網站集合中視頻檔案的總大小 c#

來源:互聯網
上載者:User

標籤:sharepoint

視頻檔案類型為:.avi .mov .rm .rmvb .wmv .asf .asx .mpg .mpeg .3gp .mp4 .flv .mkv .vob

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 video fies in all Site collection.eg: .avi,.mov,.rm,.rmvb,.wmv,.asf,.asx,.mpg,.mpeg,.3gp,.mp4,.flv,.mkv,.vob");
            string pattern = @"(\.avi|\.mov|\.rm|\.rmvb|\.wmv|\.asf|\.asx|\.mpg|\.mpeg|\.3gp|\.mp4|\.flv|\.mkv|\.vob)$";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);

            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\tSize\tSizeOfVersions\tTotalSize\tWebUrl");
            writer.WriteLine("Name\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,300000);
                /*  // 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);               
                          }
               */
                string siteUrl = site.Url;
                Int64 sizes = 0;
                Int64 historySizes = 0;
                Int64 totalSizes = 0;
                foreach (DataRow oRow in oDtRawData.Rows)
                 {                    
                    //Console.WriteLine("Processing......" + oRow["LeafName"].ToString());                                
                     if (regex.IsMatch(oRow["LeafName"].ToString()))
                     {
                         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;
                        
                        // 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["Size"].ToString() + "\t" + oRow["SizeOfVersions"].ToString() + "\t" + oRow["TotalSize"].ToString() + "\t" + oRow["WebUrl"].ToString());
                        
                     }

                    }
                if(totalSizes != 0)
                {
                    Console.WriteLine("#SUM\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("#SUM\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{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{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();
           
        }


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

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


本文出自 “博深” 部落格,轉載請與作者聯絡!

sharepoint 統計所有網站集合中視頻檔案的總大小 c#

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.