Monday, August 20, 2012

How to Change the UI Version of the Sharepoint Using Console Application

How to Change the UI Version of the Sharepoint Using Console Application:

After Migrate Sharepoint 2007 to Sharepoint 2010,you need change the version of your site otherwise it looks similar to Sharepoint 2007 site.

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using Microsoft.SharePoint;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Administration;

namespace VisualUpgrade
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite("http://server/sites/"))
            {
                SPWebCollection sites = siteCollection.AllWebs;
                foreach (SPWeb site in sites)
                {
                    try
                    {
                        Console.WriteLine("Site Version: {0}  Site Version Configuration: {1}",      
                        site.UIVersion.ToString(),  site.UIVersionConfigurationEnabled.ToString());

                        Console.WriteLine(site.Title + site.Url);
                        site.UIVersion = 4; //UI Version 3 or 4
                        site.UIVersionConfigurationEnabled = true;
                        site.Update();
                        Trace(site.Title + "********" + site.Url); //Log file
                    }
                    finally
                    {
                        if (site != null)
                            site.Dispose();
                    }
                }
            }
            Console.Read();
        }
        public static void Trace(string stritrace)
        {
            Stream codeFile = File.Open("c:\\Logs.txt", FileMode.Append);
            StreamWriter Tex = new StreamWriter(codeFile); ;
            Tex.WriteLine(DateTime.Now.ToString() + " " + stritrace);
            Tex.Write(Tex.NewLine);
            Tex.Close();
        }

    }
}

No comments:

Post a Comment