Silverlight XML Save does not overwrite the entire file

霸气de小男生 提交于 2019-12-24 03:22:18

问题


The best way to explain my problem is by a example.

I have a Xml file with some elements in it. When I remove a element, I save the file again and this problem occurs:

Before save

    <?xml version="1.0" encoding="utf-8"?>
<ElementTree>
  <Elements1 />
  <Elements2>
    <Element Name="TestElement" ID="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
  </Elements2>
  <Elements3 />
</ElementTree>

After save

<?xml version="1.0" encoding="utf-8"?>
<ElementTree>
  <Elements1 />
  <Elements2 />
  <Elements3 />
</ElementTree>D="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
  </Elements2>
  <Elements3 />
</ElementTree>

What I suspect it is doing: It keeps writing the text untill it has reached the end of the text to be saved and then it stops. It does not remove the text that is still writen in the file AFTER the last character in the stream.

How can I fix this?


回答1:


Make sure you replace the existing file when opening it and you close the stream correctly.



来源:https://stackoverflow.com/questions/11032253/silverlight-xml-save-does-not-overwrite-the-entire-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!