I have an XML document in my project that looks like this
<?xml version="1.0" encoding="utf-8" ?>
<event>
<name>Test Event</name>
<date>06/19/1967</date>
<description>Birthday</description>
<blogURL></blogURL>
</event>
I want to create a webpage that accepts user input and replaces these values.
Here is my aspx page
<asp:Panel ID="NewEvent" CssClass="eventSection" runat="server" Visible="false">
<asp:Label runat="server" ID="MessageBox" Text="" Visible="false"></asp:Label>
<telerik:RadTextBox ID="NewEventName" placeholder="Event Name" runat="server"></telerik:RadTextBox>
<br />
<telerik:RadDatePicker ID="NewDate" runat="server"></telerik:RadDatePicker>
<br />
<telerik:RadTextBox ID="NewDescription" runat="server" placeholder="Description of event" TextMode="MultiLine"></telerik:RadTextBox>
<br />
<telerik:RadTextBox ID="NewURL" runat="server" placeholder="Leave blank if none"></telerik:RadTextBox>
<br />
<telerik:RadButton ID="EditXML" runat="server" Text="Submit Event" OnClick="EditXML_Click"></telerik:RadButton>
</asp:Panel>
My code behind to grab these values
string newEventName = NewEventName.Text;
string newEventDescription = NewDescription.Text;
string newEventDate = NewDate.SelectedDate.Value.Date.ToString();
string newEventURL = NewURL.Text;
And finally, actually inserting values into xml document
XDocument doc = XDocument.Load("/PressSection.xml");
doc.Element("name").Value = newEventName;
doc.Element("date").Value = newEventDate;
doc.Element("description").Value = newEventDescription;
doc.Element("blogURL").Value = newEventURL;
doc.Save(Server.MapPath("~/PressSection.xml"));
The XML file is located in the same directory as my aspx file
What I have tried
string path = Server.MapPath("PressSection.xml");
XDocument doc = XDocument.Load(path);
which gives this error
Which I'm not sure why. When I set a break point and hover over my values, they are filled.
I've also tried
XDocument doc = XDocument.Load(Server.MapPath("~/PressSection.xml"));
Which gives me the same error as above.
Finally, I've also tried
XDocument doc = XDocument.Load("\\PressSection.xml");
Which gives me this error
I don't know what to do at this point.