Finding the Web.config file of SharePoint Site Programatically (Sharepoint2010)


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

namespace ConsoleOperations
{
    class SharepointWebConfigProgram
    {
        static void Main(string[] args)
        {

            using (SPSite oSite = new SPSite("http://localhost:5050"))
            {

                string physicalPath = oSite.WebApplication.IisSettings[SPUrlZone.Default].Path.ToString(); //Find the physical path of the Site
                Console.WriteLine(physicalPath + @"\web.config");
                Console.ReadLine();
//Copying The Web.config file
                File.Copy(physicalPath + @"\web.config", physicalPath + @"\web.config_backup_" + DateTime.Now.ToString("dd_mm_yyyy_hh_mm_ss") + ".config");
            }

        }
    }
}

Comments

Popular posts from this blog

javascript to get the all site user in sharepoint 2010 (Getting all Site users using Client Object Model)

Adding Navigation Links To Quick Launch Bar Programatically (SharePoint 2010)

Disable all day event, Recurrence,Workspace Fields in Calendar list