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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
OMC2000Commented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.