Tuesday 13 May 2008

Switching off Versioning for Content Deployment

I don't know if any of you are using content deployment, but for those who are, you would have realised that the destination db is usually the same size as the source (if not bigger). The main reason for this is every time you deploy, it creates a new version of the document. The best way to get round this is to switch off versioning. Here's a little script i've written where you pass in the URL and it will switch off versioning for every list in every site.



class Program
{
static void Main(string[] args)
{
string strurl = args[0];
try
{
using (SPSite spsite = new SPSite(strurl))
{
SPWebCollection web = spsite.AllWebs;
for (int i = 0; i < web.Count; i++)
{
foreach (SPList list in web[i].Lists)
{
if (list.EnableVersioning)
{
list.EnableVersioning = false;
list.Update();
}
}
}
spsite.Dispose();
Console.WriteLine("Application run successfully!");
}
}
catch (Exception e) {
Console.WriteLine(e.Message);
}
}
}

Let me know if you have any problems running it. Sorry about the formating of the code, this blog editor doesn't import in properly from VS2005.

Fadi

No comments: