---
title: "C# XDocument Save copy file and appends edited to end"  
description: "C# XDocument Save copy file and appends edited to end"  
author: "Samuel Fernandes"  
published: 2013-12-18  
updated: 2013-12-18  
canonical: https://www.mindstick.com/forum/1814/c-sharp-xdocument-save-copy-file-and-appends-edited-to-end  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# C# XDocument Save copy file and appends edited to end

When I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to edit XML Element and save it, it generates [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) (with edited element) and appends it to end of [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp).

var localStore = IsolatedStorageFile.GetUserStoreForApplication();

IsolatedStorageFileStream [stream](https://yourviews.mindstick.com/view/88509/us-intercepts-iranian-tanker-m-t-stream-amid-hormuz-tensions) = new IsolatedStorageFileStream("DataFolder\\PlayerData.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, localStore);

var doc = XDocument.Load(stream);

doc.[Root](https://answers.mindstick.com/qa/49855/tell-me-what-is-root-port-in-spanning-tree-protocol).Element("[characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters)").Element("[character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character)").SetElementValue("expierence", 10);

doc.Save(stream, SaveOptions.None);

stream.Close();

Example [output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) file:

<?xml [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version)="1.0" [encoding](https://www.mindstick.com/interview/752/how-is-encoding-handled-in-ajax)="utf-8"?>

<root>

<characters>

<character>

<expierence>0</expierence>

</character>

</characters>

</root><?xml version="1.0" encoding="utf-8"?>

<root>

<characters>

<character>

<expierence>10</expierence>

</character>

</characters>

</root>

## Replies

### Reply by Anonymous User

Hi Samuel,

That's exactly what you told it to do by passing FileMode.OpenOrCreate.

If you want to truncate any existing file, pass Create.


---

Original Source: https://www.mindstick.com/forum/1814/c-sharp-xdocument-save-copy-file-and-appends-edited-to-end

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
