Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

The below requirement is similar to the Crash and Recovery concept in Microft Word/Excel.

The user will enter data into 'n' no. of text boxes and select 'n' no of drop down values in a single form. So whenever he enters those value that has to be wrriten in an XML file. So that even if his form crashes at anytime when he logs into the same link again we need to provide him a provision that load local memory data. So whenever he clicks the button to load local data all the controls should get loaded with the already entered data which has been stored locally.


Is there a way to achive this ?
Even if there is any other approach that we can follow other than saving in XML file Please share that too....


Thanks & Regards,
Mathi.
Posted
Updated 20-May-13 1:30am
v2
Comments
Rockstar_ 20-May-13 7:36am    
it already stores in viewstate , no need to store manually...
Mathi2code 24-May-13 4:07am    
Hi Member61 Thanks for replying and need some help
If it already stores in viewstate how to retrieve it? is there any sample for that?Lets say,
I have some 50 controls in my application so will all the values be stored in viewstate
How can store it... Please share code sample which would be great....

1 solution

you can create XML file in FormClosing Event having node representing each control on the Form.
Represent each control as separate node inside the XML file.
eg
For combo-box you need to create combo-box node having all decedent node representing items of combo-box.
XML
<combobox id="City">
<item id="one" selected="True">Mumbai</item>
<item id="two" selected="False">Gujarat</item>
</combobox>

During Form Load event read the XML and assign value of respective note to respective control.
Following is the code to Create XML file.
C#
private static void Main()
       {
           XmlDocument doc = new XmlDocument();
           XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
           doc.AppendChild(docNode);

           XmlNode productsNode = doc.CreateElement("products");
           doc.AppendChild(productsNode);

           XmlNode productNode = doc.CreateElement("product");
           XmlAttribute productAttribute = doc.CreateAttribute("id");
           productAttribute.Value = "01";
           productNode.Attributes.Append(productAttribute);
           productsNode.AppendChild(productNode);

           XmlNode nameNode = doc.CreateElement("Name");
           nameNode.AppendChild(doc.CreateTextNode("Java"));
           productNode.AppendChild(nameNode);
           XmlNode priceNode = doc.CreateElement("Price");
           priceNode.AppendChild(doc.CreateTextNode("Free"));
           productNode.AppendChild(priceNode);

           doc.Save(@"Path");
       }

Following is the result of above mention code.
XML
<?xml version="1.0" encoding="UTF-8"?><products>-<product id="01"><Name>Java</Name><Price>Free</Price></product></products>

You can use XDocument also. ie using System.Xml.Linq;
Quick example
C#
XDocument doc = new XDocument();
XElement docElement=new XElement("City");
doc.Add(docElement);
docElement.Add(new XElement("Thane"));
docElement.Add(new XElement("Pune"));
doc.Save(@"Path");
 
Share this answer
 
v4
Comments
Mathi2code 22-May-13 13:16pm    
could you please provide me an example for using XDocument (System.Xml.Linq;)
Amey K Bhatkar 24-May-13 10:49am    
done
Mathi2code 28-May-13 2:35am    
Thanks a lot Amey...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900