XML is a data description language, the structure is relatively simple, not professionals can also read the language described in the content. XML represents the abbreviation for Extensible Markup Language (extensible Markup Language, meaning Extensible Markup Language). XML is a set of rules that define semantic markup that divides documents into many parts and identifies them. It is also a Meta markup language, defined as a syntactic language for defining other semantic, structured markup languages related to a particular domain.
Ways to save XML data:
In asp.net 2.0, the "XmlDocument" class is used to implement the operation of XML data to achieve the purpose described at the beginning of the article. The steps to implement the method are as follows:
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.OleDb"%>
<script language= "VB" runat= "Server" >
Sub Page_Load (Sender as Object, E as EventArgs)
Dim strconnection as String
Dim strSQL as String
Dim Objdataset as New DataSet ()
Dim Objconnection as OleDbConnection
Dim Objadapter as OleDbDataAdapter
' Set the connection and query details
strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=" & Server.MapPath ("Northwind.mdb")
strSQL = "Select FirstName, LastName from Employees;"
' Open ' connection and set the command
Objconnection = New OleDbConnection (strconnection)
Objadapter = New OleDbDataAdapter (strSQL, objconnection)
' Fill the DataSet with the ' data
Objadapter.fill (Objdataset, "Employees")
Objdataset.writexml (Server.MapPath ("Employees.xml"))
Response.Write ("<a href= ' employees.xml ' >view xml file</a>")
End Sub
</script>
This article is an example of how to save DataGridView data to a txt document in asp.net
Using System.IO
public void SaveFile ()
{
Instantiate a Save File dialog box
SaveFileDialog SF = new SaveFileDialog ();
Set File Save type
sf. Filter = "TXT file |*.txt";
If the user does not enter an extension, the suffix is appended automatically
sf. AddExtension = true;
Set Title
sf. Title = "Write file";
If the user clicks the Save button
if (SF. ShowDialog () = = DialogResult.OK)
{
Instantiate a file stream---> associated with a write file
FileStream fs = new FileStream (SF. FileName, FileMode.Create);
Instantiate a streamwriter--> associated with FS
StreamWriter sw = new StreamWriter (FS);
Start writing
if (This.dataGridView1.Rows.Count < 1)
{
MessageBox.Show ("No data!") Export failed! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Else
{
for (int i = 0; i < this.datagridview1.rows.count-1 i)
{
Sw. WriteLine (This.datagridview1.rows[i]. Cells[0]. Value.tostring ());
}
Sw. Write (This.textBox1.Text);
Empty buffer
Sw. Flush ();
Close the stream
Sw. Close ();
Fs. Close ();
MessageBox.Show ("Save success!") "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}