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

SharePoint 2010: JavaScript Code To Check if user exists in a group (ECMA)

How to copy DLLs from GAC.