What differences UTF-8 and UTF-8 without BOM ??

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Hi all,

 What differences UTF-8 and UTF-8 without BOM ??

<b>byte-order mark</b> (<b>BOM</b>)
http://en.wikipedia.org/wiki/Byte_Order_Mark <font color="#0072bc http://en.wikipedia.org/wiki/Byte_Order_Mark</font>


My issue ( http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/73cb2147-2d4f-4a40-b343-498393b1d23c http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/73cb2147-2d4f-4a40-b343-498393b1d23c , thanks Xun Ye)


I have an app.config (UTF-8 format file). I create an application winforms for changes and save configuration programatically.
When I save changes the format file changes to UTF-8 without BOM:( but I need format file UTF-8, and too when I open app.config and changed it, Visual Studio  save it like UTF-8.


I try explain it again

Steps:

0. app.config has <?xml version="1.0" encoding="utf-8" ?> in first line, and UTF-8 format.

1. Open app.config file using ConfigurationManager class. The app.config file has UTF-8 format.

2. I changes some values in configuration and I save this changes using

config.Save(ConfigurationSaveMode.Modified);

3. I check the format of app.config file (that was saved) and now has UTF-8 without BOM format. I want utf-8 after saving changes...



Before save changes, the format file is UTF-8.

After save the app.config, now the format is UTF-8 without BOM

( Im using Notepad++ like text editor, and it appears ANSI as UTF-8).
Any suggestions or comments, please ? I need help about it
Thanks in advance. See code below please
My code is:
string rutaConfig= tbRutaConfigServicioIndexado.Text;
// Map to the application configuration file.
ExeConfigurationFileMap configFile= New ExeConfigurationFileMap();
configFile.ExeConfigFilename = rutaConfig;
Configuration config= ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
string[] keys = config.AppSettings.Settings.AllKeys;
KeyValueConfigurationCollection settings1= config.AppSettings.Settings();
settings1("PDF_CREADOR").Value = tbServicioIndexadoPDF_CREADOR.Text;
config.ConnectionStrings.ConnectionStrings["SQLConnection"].ConnectionString = tbCadenaConexionFirmasParaServicioIndexado.Text;
// Modifica el app.config pero pierde los comentarios del appsettings
config.Save(ConfigurationSaveMode.Modified);

ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config);
            ChannelEndpointElementCollection listaEndpoints = sectionGroup.Client.Endpoints;
            if (listaEndpoints.Count >= 2)
            {
                ChannelEndpointElement endpoint = null;
                ChannelEndpointElement endpoint2 = null;
                // Endpoint Agente Servicio Base
                endpoint = BuscarEndpointClientePorNombre(listaEndpoints, "AgenteServicioBase");
                endpoint.Address = new Uri(endpointAgenteServicioBase);
                // Endpoint Agente Log
                endpoint2 = BuscarEndpointClientePorNombre(listaEndpoints, "AgenteLog");
                endpoint2.Address = new Uri(endpointAgenteLog);
            }

            config.Save(ConfigurationSaveMode.Modified); <hr size="1" align="left" width="25% http://www.alhambra-eidos.es/web2005/index.html

View the full article
 
Back
Top