I have an application that changes your connectionstring in a webconfig in your unauthorized exception. Is there a way I can allow the file to be accessed? Thanks for any help.
Exception Message: System.UnauthorizedAccessExeption: Access to the path "PATH" is denied. //File path to xml file
var adminConnectionStringConfig = new FileInfo(e.Data.Details.VSStudio.Solution.FullName).Directory
+ @"\Web.Admin\ConnectionStrings.config";
//Method that updates the xml file
private void SetupConnectionStrings(string path, string newDb)
{
var doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("configuration/connectionStrings");
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Attributes["name"].Value == "SYS")
{
//Get ConnectionString for client project
var connectionString = node.ChildNodes[i].Attributes["connectionString"].Value;
// Cut all
var dbName = node.ChildNodes[i].Attributes["connectionString"]
.Value.Substring(connectionString.IndexOf("Catalog="));
dbName = dbName.Replace("Catalog=", "");
//Db Name that we will now replace
dbName = dbName.Substring(0, dbName.IndexOf(";"));
// System.Diagnostics.Debugger.Launch();
doc.InnerXml = doc.InnerXml.Replace(dbName, newDb);
doc.Save(path);
break;
}
}
}