Ever wanted to get a report on versioning sizes on SharePoint? Unlimited No. of versions enabled in various document library across web application. As part of regular auditing, wanted to generate report for the entire web application ,with Number of versions, Amount of storage consumed by versions. Of course there are some third-party products like Axceler Control Point with additional capabilities. But How about wring my own code? Sounds good.
Here is my code:
Tested in SharePoint 2010 and MOSS 2007.
Here is my code:
Tested in SharePoint 2010 and MOSS 2007.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.IO; namespace SharePointReporting { class GetVersioningReport { static void Main( string [] args) { string site; StreamWriter SW; try { if (args.Length == 0) { Console.WriteLine( "Enter the Web Application URL:" ); site = Console.ReadLine(); } else { site = args[0]; } SPSite tmpRoot = new SPSite(site); SPSiteCollection tmpRootColl = tmpRoot.WebApplication.Sites; //objects for the CSV file generation SW = File.AppendText( "c:\\VersioningReport.csv" ); //Write the CSV Header SW.WriteLine( "Site Name, Library, File Name, File URL, Last Modified, No. of Versions, Latest Version Size -KB,Total Versions Size - MB" ); //Enumerate through each site collection foreach (SPSite tmpSite in tmpRootColl) { //Enumerate through each sub-site foreach (SPWeb tmpWeb in tmpSite.AllWebs) { //Enumerate through each List foreach (SPList tmpList in tmpWeb.Lists) { //Get only Document Libraries & Exclude specific libraries if (tmpList.BaseType == SPBaseType.DocumentLibrary & tmpList.Title!= "Workflows" & tmpList.Title!= "Master Page Gallery" & tmpList.Title!= "Style Library" & tmpList.Title!= "Pages" ) { foreach (SPListItem tmpSPListItem in tmpList.Items) { if (tmpSPListItem.Versions.Count > 5) { SPListItemVersionCollection tmpVerisionCollection = tmpSPListItem.Versions; //Get the versioning details foreach (SPListItemVersion tmpVersion in tmpVerisionCollection) { int versionID = tmpVersion.VersionId; string strVersionLabel = tmpVersion.VersionLabel; } //Get the versioning Size details double versionSize = 0; SPFile tmpFile = tmpWeb.GetFile(tmpWeb.Url + "/" + tmpSPListItem.File.Url); foreach (SPFileVersion tmpSPFileVersion in tmpFile.Versions) { versionSize = versionSize + tmpSPFileVersion.Size; } //Convert to MB versionSize= Math.Round(((versionSize/1024)/1024),2); string siteName; if (tmpWeb.IsRootWeb) { siteName= tmpWeb.Title + " - Root" ; } else { siteName=tmpSite.RootWeb.Title + " - " + tmpWeb.Title; } //Log the data to a CSV file where versioning size > 0MB! if (versionSize > 0) { SW.WriteLine(siteName + "," + tmpList.Title + "," + tmpSPListItem.Name + "," + tmpWeb.Url + "/" + tmpSPListItem.Url + "," + tmpSPListItem[ "Modified" ].ToString() + "," + tmpSPListItem.Versions.Count + "," + (tmpSPListItem.File.Length / 1024) + "," + versionSize ); } } } } } } } //Close the CSV file object SW.Close(); //Dispose of the Root Site Object tmpRoot.Dispose(); //Just to pause Console.WriteLine( @"Versioning Report Generated Successfull at c:\VersioningReport.csv. Press ""Enter"" key to Exit" ); Console.ReadLine(); } catch (Exception ex) { System.Diagnostics.EventLog.WriteEntry( "Get Versioning Report" , ex.Message); } } } } |
Add a pivot table to make the SharePoint version history report little more meaningful.
I've Created a Project in CodePlex for this utility: http://versioningsizereport.codeplex.com/ .
For PowerShell version of the above code, Refer my another post: SharePoint Document Versions Size Report with PowerShell
Reference:
http://www.sharepointdiary.com/2012/02/versioning-size-report-for-sharepoint.html
No comments:
Post a Comment