Monday, March 3, 2014

Modify Web.Config using visual studio or powershell to specific web application


I have a problem in modifying web.config to specific web application I've search and try so many solution, when i deploy, the modification still affect to all existing web application


here is my code part of my code :



public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebService service = SPWebService.ContentService;
SPWebConfigModification myModification = new SPWebConfigModification();

SPSite site = new SPSite("http://win-a52s8epvot4:888/");
SPWeb web = site.OpenWeb();

myModification.Path = "configuration/appSettings";
myModification.Name = "add[@key='SQLArchiveConnectionString'][@value='Data Source=WIN-A52S8EPVOT4;Initial Catalog=TRAEmployee;User ID=sa;Password=P@ssw0rd;Persist Security Info=False;']";
myModification.Sequence = 0;
myModification.Owner = "administrator";
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
myModification.Value = "<add key='SQLArchiveConnectionString' value='Data Source=WIN-A52S8EPVOT4;Initial Catalog=TRAEmployee;User ID=sa;Password=P@ssw0rd;Persist Security Info=False;' />";
web.Site.WebApplication.WebConfigModifications.Add(myModification);

service.Update();
service.ApplyWebConfigModifications();
}

is there any suggestion for my problem ?


your reply will greatly help me to finish this problem


Regards,


Jay






No comments:

Post a Comment