using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO; //this
using System.Text; //this
using System.Xml; //this
/// <summary>
/// 生成XML文件
/// </summary>
private void writeXml()
{
try
{
string strName = Guid.NewGuid().ToString().Replace("-","");
Session["filename"] = "Read" + strName + ".xml";
string sFilePath = Server.MapPath("../TempFiles/" + Session["filename"].ToString());
XmlTextWriter writer = new XmlTextWriter(sFilePath, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("INPUT");
writer.WriteStartElement("TextBox");
foreach (Control ctl in form1.Controls)
{
if (ctl.GetType().Name == "TextBox")
{
TextBox tb = new TextBox();
tb = (TextBox)this.FindControl(ctl.ID);
writer.WriteElementString(tb.ID, tb.Text);
}
else if (ctl.GetType().Name == "DropDownList")
{
DropDownList tb = new DropDownList();
tb = (DropDownList)this.FindControl(ctl.ID);
writer.WriteElementString(tb.ID, tb.SelectedItem.Text);
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
catch (Exception ex)
{
throw ex;
}
}
private void loadXml(string strFileName)
{
DataSet mydds = new DataSet();
string sFilePath = Server.MapPath("../TempFiles/" + strFileName);
//Session.Remove("filename");
if (File.Exists(sFilePath))
{
mydds.ReadXml(sFilePath);
for (int i = 0; i < mydds.Tables[0].Columns.Count; i++)
{
try
{
TextBox tbx = new TextBox();
tbx = (TextBox)this.FindControl(mydds.Tables[0].Columns[i].ColumnName);
tbx.Text = mydds.Tables[0].Rows[0][i] + "";
}
catch (Exception ex)
{
throw ex;
}
}
}
else
{
Session.Remove("filename");
throw new Exception("Custm");
}
}