Export Datagrid to Excel File and Save Without Prompt

I'm using the following subroutine to export a datagrid to Excel. I'm going set it up to create a unique filename and predefined save location.

What do I need to do to get it to save without prompting the user?

Thanks.
Protected Sub Export_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles export.Click
        Dim stringWrite As IO.StringWriter
        Dim htmlWrite As HtmlTextWriter
        Dim frm As HtmlForm = New HtmlForm()

        Response.Clear()

        Response.AddHeader("content-disposition", "attachment;filename=BarcodeScannerRpt.xls")

        Response.Charset = ""

        Response.ContentType = "application/vnd.ms-xls"

        stringWrite = New IO.StringWriter

        htmlWrite = New HtmlTextWriter(stringWrite)

        Controls.Add(frm)
        frm.Controls.Add(GridView1)
        frm.RenderControl(htmlWrite)

        Response.Write(stringWrite.ToString())

        Response.End()
    End Sub

Open in new window

LVL 1
JB4375Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
OMC2000Connect With a Mentor Commented:

Then you don't need code, which generates content for downloading.
Just write it to file on the server instead of writing into Response. You would need write permissions for ASPNET user.
0
 
OMC2000Commented:

I think it must be impossible without ActiveX or other component installed on a client computer/

Actually you want to write something on user computer without his approval.
Server must prevent you from doing so due to security reasons.

Otherwise you would be able to save your own version of windows dlls to system32 for instance
0
 
JB4375Author Commented:
I'm just wanting to save it to a folder on a server. I've seen it done in VBScript for logfiles, and for backups of notification letters in word doc formats when accounts are created, for example.
0
 
JB4375Author Commented:
Funny how a little dialogue will get you thinking the on the right track. I pulled some code from an existing vbscript and was looking at the same thing.
Thanks!!
0
 
JB4375Author Commented:
Thanks!!
0
All Courses

From novice to tech pro — start learning today.