Ошибка несанкционированного доступа к файлу в C#
я делаю изменения в файле .xml в его атрибутивном значении, но это дает ошибку несанкционированного доступа.
Что я уже пробовал:
<pre> try { string path =Application.StartupPath + "\\OTS.exe.config"; var doc = new XmlDocument(); doc.Load(path); XmlNodeList endpoints = doc.GetElementsByTagName("connectionStrings"); foreach (XmlNode item in endpoints) { if (item.HasChildNodes) { foreach (var c in item.ChildNodes) { if (((XmlNode)c).NodeType == XmlNodeType.Element) { var adressAttribute = ((XmlNode)c).Attributes["name"]; if (adressAttribute.Value.Contains("OTSConnection")) { ((XmlNode)c).Attributes["connectionString"].Value = connection_string; //((XmlNode)c).Attributes["providerName"].Value = SetupConstants.DbEmbededConnectionProvider; } } } } } doc.Save(path); // it is not saving the file. jump to catch block. string exePath = Path.Combine(path,"OTS.exe"); return true; } catch { return false; }