Here is my example code on what I am trying to do, can you give an example syntax to make this possible?
The query select will run to show data on datalist and after that if button is click the results will be written to an HTML file.
Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataList();
}
}
Data List
public void DataList()
{
String testcon = System.Configuration.ConfigurationManager.ConnectionStrings["TestConnection"].ToString();
MySqlConnection con = new MySqlConnection(testcon );
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * From ExampleTable";
cmd.ExecuteNonQuery();
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
Button Click
protected void Button1_Click(object sender, EventArgs e)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
using (FileStream fs = new FileStream((path + "\\Sample.html"), FileMode.Create))
{
using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine("<html>");
w.WriteLine("</head>");
w.WriteLine("<body>");
w.WriteLine("DataList(ItemTemplate)");
w.WriteLine("</body>");
w.WriteLine("</html>");
}
LabelDisplay.Text = "File Successfully Created @ " + ((path + "\\Sample.html"));
}
}