File stream Gridview to Excel
Hi
I need help in this part. I need to send and attachment(.xls file) which contains the data in the gridview of my page where users chooses the data. My Gridview will then filter out and give me the details of those whose data matching the filtering conditions.
I then will have to export these data into an excel file, which I will email these details out immediately. I want the saving of the file to be in the background unlike the codes that I have now, which prompts me on whether I want to save, open, or cancel. I do not want the user to do anything to that exported file. The codes that I have now keeps prompting me on the above 3 options, which I now know is wrong to yse Response.write because I have been told that it is of the wrong direction. I've read on topic here that says using file stream will help. My ASP.NET still isn't good enought to understand what was needed and how could I come along it?
Below are the old codes for Respnose.Write:
Dim stringWrite As IO.StringWriter
Dim htmlWrite As HtmlTextWriter
Dim frm As HtmlForm = New HtmlForm()
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=tryexcel.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
stringWrite = New IO.StringWriter
htmlWrite = New HtmlTextWriter(stringWrite)
Controls.Add(frm)
frm.Controls.Add(GridView1)
frm.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
Please help, thank you!
|