Using Interop.Excel to generate excel file and export to excel

I am using the interop.excel to generate an excel file that I will be exporting to excel. It works fine if I save it to my C drive. But I want to be able to export to excel and give the user a file download prompt with the opens save, open or cancel. If I use
Response.AddHeader("content-disposition","attachment;filename=Hello.xls")
Response.ContentType="application/vnd.ms-excel"
Response.Write(MyWorkBook)
my opened window hangs. Any suggestions?
RylaAsked:
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.

kishoreb123Commented:
pl try Response.BinaryWrite()
0
Neil FlemingConsultant and developerCommented:
try using a stringwriter:


Dim sw As New StringWriter()
       httpContext.Current.Response.ClearContent()
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & filename)
        HttpContext.Current.Response.ContentType = "application/vnd.xls"
        HttpContext.Current.Response.Charset = ""

HttpContext.Current.Response.Write(sw.ToString())
HttpContext.Current.Response.End()

sw.Dispose()

Open in new window

0
RylaAuthor Commented:
NeilFleming1, Do you think this will solve the Excel 2007 issue of the warning "The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Neil FlemingConsultant and developerCommented:
No -- sadly it doesn't solve that little excitement, which is caused by MS's "security feature" caled 'Extension Hardening' (at least someone at MS has a sense of humor....)

Your choices are to use xlsx files (useless if anyone is using excel 2003), CSV files, or modify the client PC's registry to turn off the Extension checking.

Instructions on how to do that are here:

 http://blogs.msdn.com/vsofficedeveloper/pages/Excel-2007-Extension-Warning.aspx

...bu obviously of no use unless you have access to every machine that will open your file.

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
Neil FlemingConsultant and developerCommented:
PS Microsoft's own advice is to ignore the warning -- the file opens fine in any case.
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
.NET Programming

From novice to tech pro — start learning today.