By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

Save Configuration dynamically without lost comments

P: n/a
Hi, thanks, mister

The code

string rutaConfig = tbRutaConfigServicioBase.Text;

'// Map to the application configuration file.

ExeConfigurationFileMap configFile = New ExeConfigurationFileMap();

configFile.ExeConfigFilename = rutaConfig;

Dim config As Configuration =
ConfigurationManager.OpenMappedExeConfiguration(co nfigFile,
ConfigurationUserLevel.None);

string[] keys = config.AppSettings.Settings.AllKeys;
KeyValueConfigurationCollection settings1 = config.AppSettings.Settings();

settings1("GRUPOBACKUP.Ruta_Grabar_Ficheros").Valu e =
tbGRUPOBACKUP_Ruta_Grabar_Ficheros.Text;
settings1("SERVIDOR_INDEXADO").Value = tbSERVIDOR_INDEXADO.Text;

settings1("PDF_CREADOR").Value = tbPDF_CREADOR.Text;

settings1("PDF_AUTOR").Value = tbPDF_AUTOR.Text;

settings1("PDF_TITULO").Value = tbPDF_TITULO.Text;

settings1("PDF_ASUNTO").Value = tbPDF_ASUNTO.Text;
config.ConnectionStrings.ConnectionStrings["SQLConnection"].ConnectionString
= tbCadenaConexionFirmasParaServicioBase.Text;

config.ConnectionStrings.ConnectionStrings["SQLConnectionSecundaria"].ConnectionString = tbCadenaConexionOGFParaServicioBase.Text;

' Modifica el app.config pero pierde los comentarios del appsettings

' As√* se modifica el app.config pero a√Īade secciones vac√*as, modifica
bastante la estructura. Adem√°s al utilizar EnterpriseLibrary se producen
errores de ensamblados

config.Save(ConfigurationSaveMode.Modified, True); ' <==== Fails here !!!
The error:

System.Configuration.ConfigurationErrorsException was unhandled
BareMessage="Se ha producido un error al crear el controlador de sección
de configuración para exceptionHandling: No se puede cargar el archivo o
ensamblado 'Microsoft.Practices.EnterpriseLibrary.ExceptionHa ndling,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' ni una de sus
dependencias. El sistema no puede hallar el archivo especificado."
Filename="C:\Archivos de programa\GRUPO BACKUP\GRUPO BACKUP Servicios
Principales OGF\ServicioBase.exe.config"
Line=5
Message="Se ha producido un error al crear el controlador de sección de
configuración para exceptionHandling: No se puede cargar el archivo o
ensamblado 'Microsoft.Practices.EnterpriseLibrary.ExceptionHa ndling,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' ni una de sus
dependencias. El sistema no puede hallar el archivo especificado.
(C:\Archivos de programa\GRUPO BACKUP\GRUPO BACKUP Servicios Principales
OGF\ServicioBase.exe.config line 5)"
Source="System.Configuration"
StackTrace:
en
System.Configuration.BaseConfigurationRecord.FindA ndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
en
System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
en System.Configuration.BaseConfigurationRecord.GetSe ction(String
configKey, Boolean getLkg, Boolean checkPermission)
en System.Configuration.ConfigurationSectionCollectio n.Get(String name)
en
System.Configuration.ConfigurationSectionCollectio n.<GetEnumerator>d__0.MoveNext()
en
System.Configuration.Configuration.ForceGroupsRecu rsive(ConfigurationSectionGroup group)
en System.Configuration.Configuration.SaveAsImpl(Stri ng filename,
ConfigurationSaveMode saveMode, Boolean forceSaveAll)
en System.Configuration.Configuration.Save(Configurat ionSaveMode
saveMode, Boolean forceSaveAll)
en
GRUPOBACKUP.InstaladorConfiguradorOGF.Cliente.Util .FPrincipal.bGuardarConfiguracionServicioBase_Clic k(Object
sender, EventArgs e) en
D:\DESA\ExpedienteElectronico\Instalacion\Instalad orConfigurador\GRUPOBACKUP.InstaladorConfiguradorO GF.Cliente.Util\FPrincipal.vb:l√*nea 231
en System.Windows.Forms.Control.OnClick(EventArgs e)
en System.Windows.Forms.Button.OnClick(EventArgs e)
en System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
en System.Windows.Forms.Control.WndProc(Message& m)
en System.Windows.Forms.ButtonBase.WndProc(Message& m)
en System.Windows.Forms.Button.WndProc(Message& m)
en
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
en System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
en System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
en
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
en
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
en
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
en System.Windows.Forms.Application.Run(Form mainForm)
en GRUPOBACKUP.InstaladorConfiguradorOGF.Program.Main () en
D:\DESA\ExpedienteElectronico\Instalacion\Instalad orConfigurador\GRUPOBACKUP.InstaladorConfiguradorO GF\Program.cs:l√*nea 19
en System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
en Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
en System.Threading.ThreadHelper.ThreadStart_Context( Object state)
en System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
en System.Threading.ThreadHelper.ThreadStart()
line 5 in app.config
<section name="exceptionHandling"
type="Microsoft.Practices.EnterpriseLibrary.Except ionHandling.Configuration.ExceptionHandlingSetting s,
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
The app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Loggin g.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
<section name="exceptionHandling"
type="Microsoft.Practices.EnterpriseLibrary.Except ionHandling.Configuration.ExceptionHandlingSetting s,
Microsoft.Practices.EnterpriseLibrary.ExceptionHan dling, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
</configSections>
<appSettings>
....
IMPORTANT: If copy assemblies of EnterpriseLibrary where I have my project
output, all works fine.
Thanks in advance.
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.com/churrosoft
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

Sep 24 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.