FileMode.Open y FileMode.OpenOrCreate la diferencia cuando existe un archivo? c # error?
He escrito ese código:
public void Save()
{
using (FileStream fs = new FileStream(Properties.Settings.Default.settings_file_path, FileMode.Open))
{
XmlSerializer ser = new XmlSerializer(typeof(MySettings));
ser.Serialize(fs, this);
}
}
Cuando estoy usandoFileMode.Open
todo está bien y la salida es e.x. Me gusta esto:
<?xml version="1.0"?>
<MySettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<settingsList>
<Setting>
<Value>12</Value>
<Name>A0</Name>
<Type>MEASUREMENT</Type>
</Setting>
<Setting>
<Value>5000</Value>
<Name>C0</Name>
<Type>MEASUREMENT</Type>
</Setting>
</settingsList>
</MySettings>
pero cuando lo cambio aFileMode.OpenOrCreate
la salida cambiará a:
<?xml version="1.0"?>
<MySettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<settingsList>
<Setting>
<Value>12</Value>
<Name>A0</Name>
<Type>MEASUREMENT</Type>
</Setting>
<Setting>
<Value>5000</Value>
<Name>C0</Name>
<Type>MEASUREMENT</Type>
</Setting>
</settingsList>
</MySettings>>
lo que hace que todo el archivo xml esté dañado debido a>
Firmar al final.
¿Es esto explicable o es un error de C #?