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
Post a Comment