Add new item to XML File

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey Guys!
I really get desperate on my current problem.
I have an XML-File looking like this:
<div style="color:black; background-color:white
<pre><span style="color:blue <?
<span style="color:#a31515 xml
<span style="color:red version
<span style="color:blue =
<span style="color:black "
<span style="color:blue 1.0
<span style="color:black "
<span style="color:red encoding
<span style="color:blue =
<span style="color:black "
<span style="color:blue utf-8
<span style="color:black "
<span style="color:blue ?>
<br/>
<span style="color:blue <
<span style="color:#a31515 Appointments
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Appointment
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Name
<span style="color:blue >
A Book<span style="color:blue </
<span style="color:#a31515 Name
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Contact
<span style="color:blue >
Brother Tuck<span style="color:blue </
<span style="color:#a31515 Contact
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Date
<span style="color:blue >
20110606<span style="color:blue </
<span style="color:#a31515 Date
<span style="color:blue >
<br/>
<span style="color:blue </
<span style="color:#a31515 Appointment
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Appointment
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Name
<span style="color:blue >
10 Dollar<span style="color:blue </
<span style="color:#a31515 Name
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Contact
<span style="color:blue >
Mike Sample<span style="color:blue </
<span style="color:#a31515 Contact
<span style="color:blue >
<br/>
<span style="color:blue <
<span style="color:#a31515 Date
<span style="color:blue >
20110113<span style="color:blue </
<span style="color:#a31515 Date
<span style="color:blue >
<br/>
<span style="color:blue </
<span style="color:#a31515 Appointment
<span style="color:blue >
<br/>
<span style="color:blue </
<span style="color:#a31515 Appointments
<span style="color:blue >
<br/>
<br/>
[/code]

<br/>

Now I want to add a new item to this list and I really dont know / understand how.<br/>
I read nearly every XML-Manual in the web, but I seem to be too stupid for them, so please dont post links to any tutorials. :S
You are my last hope!
How to add this Item?:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; string newname = <span style="color:#A31515; "TestName";
<span style="color:Blue; string newcontact = <span style="color:#A31515; "TestPerson";
<span style="color:Blue; string newdate = <span style="color:#A31515; "20101224"
[/code]

I tried it like this, but I doesnt work...

<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // Add new Item
<span style="color:Blue; var items = XElement.Load(<span style="color:#A31515; "LentItems.xml");
<span style="color:Blue; var newItem = <span style="color:Blue; new XElement(<span style="color:#A31515; "Appointment",
<span style="color:Blue; new XElement(<span style="color:#A31515; "Name", newperson),
<span style="color:Blue; new XElement(<span style="color:#A31515; "Contact", newcontact),
<span style="color:Blue; new XElement(<span style="color:#A31515; "Date", newdate)
);
items.Add(newItem);

IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();

IsolatedStorageFileStream location = <span style="color:Blue; new IsolatedStorageFileStream(<span style="color:#A31515; "LentItems.xml", FileMode.Open, FileAccess.ReadWrite, storage);
System.IO.StreamWriter file = <span style="color:Blue; new System.IO.StreamWriter(location);
items.Save(file);
[/code]

I get the following exception when I try to create the IsolatedStorageFileStream location:<br/>
Operation not permitted on IsolatedStorageFileStream.
Can anybody help me here?
You would save my week!
Thanks a lot and best greets
Robby


View the full article
 
Back
Top