-2

Sorry for simple question:

I want to load XML file by fileupload and save it in the field of Table with xml type. then restore it from sql and bind it to dropdown list with Handler?

RobertEves92
  • 145
  • 12
smittsara
  • 1
  • 1

1 Answers1

0

One of the simplest ways is to use XmlDocument to load your file and process it

XmlDocument xmlDoc= new XmlDocument(); // Create an XML document object
xmlDoc.Load("yourXMLFile.xml"); // Load the XML document from the specified file

// Get elements
XmlNodeList foo = xmlDoc.GetElementsByTagName("foo");
XmlNodeList bar = xmlDoc.GetElementsByTagName("bar"); 

// Display the results
Console.WriteLine("foo: " + foo[0].InnerText);
Console.WriteLine("bar: " + bar[0].InnerText);

Because you're using it to return ALL elements based on their known name it will pop everything into an array. This makes it a lot easier to process multiple entries, for example:

<document>
    <entry>
        <foo>foo</foo>
        <bar>bar</bar>
    </entry>
    <entry>
        <foo>foo</foo>
        <bar>bar</bar>
    </entry>
</document>

Depending on the type of data I would recommend making your own class and storing the entries in an array or list of that class.

Once that's done you can easily reference them and use .net's SQL functions to insert the entries from the list into the database

You can find details of how to bind your dropdown list to the dataset here: Populating an ASP.Net Drop Down List with DataSet data from DataSet created with DataSet designer

Community
  • 1
  • 1
RobertEves92
  • 145
  • 12