I had to put this small site together for someone and one of the things he wanted was a way to put up his own content for one of his pages. In a sense, this is a content management system in its simplest form. So I came up with, what I think, is a simple and effective way using XML as the data source. Here are the requirements for what I am doing:
The goal was to have the user login, edit his page and have the front end page read it and show it. I took it one step further and made the XML file handle multiple pages, this way in the future if he needs a few more pages, it's already setup.
First, here is the format of the XML file
As you can see, it's a very simple format.
Second, Lets look at how some of the markup will look like for the page where the editing will take place. This is a very simple format
Note: You will still need to add the code for the tinymce editor so it converts the textbox into the editor
You'll notice the DropDownList is using the XMLDataSource as it's DataSourceID. This is so we can keep track of which page we will be editing. You'll see how below in the code behind.
Here is the code behind for the Submit button
Not much huh? The XMLDataSource takes care of saving the document for you, so you don't have to worry about it. What's going on here is the following:
- We read the XML document into our own XMLDocument object
- Find the node we want based off the item in the drop down ("page" name)
- Set the text of that node to the text of the editor.
- Call the Save() method from the XMLDataSource object.
You'll notice we don't have to do any type of encoding for the editor text. The Save() method will automatically convert items as needed from what I have found. For example a < will turn into "<"
Here is some code on how to read it back out. This is explicity specifying the page name, but you could make it dynamic as needed. I chose to read this out into a LiteralControl.
Sample Markup for ASPX
Sample Code Behind for ASPX Page
That's it everybody. Simple, quick and easy. You don't have to worry about setting up any SQL database, you just need to make sure to give read/write access to the XML file you will be using. Don't forget this can handle multiple pages as well.
Note: I tested basic data entry and a copy and paste from word and all turned out ok in the XML file. I thought I would need the <![CDATA[]]> tag but I didn't...well not from what I have ran into yet.
62f1b4b3-bfdd-4f66-ab7a-fddddfd6b052|0|.0
ASP.NET
asp.net