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?

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.AddHeader("content-disposition", "attachment;filename=BarcodeScannerRpt.xls")

        Response.Charset = ""

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

        stringWrite = New IO.StringWriter

        htmlWrite = New HtmlTextWriter(stringWrite)



    End Sub

Open in new window

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.


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
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.

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.

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.
JB4375Author Commented:
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

From novice to tech pro — start learning today.