Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Saving datagrid as Excel file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RSH - 05 Jun 2007 13:44 GMT
Hi,

Im using the code below to render a datagrid as an Excel file.  It seems to
work fine when the user clicks on the Save button.  But when they click on
the open button, it renders correctly but when the user attempts to save the
document from the browser...it saves it as an HTML file.  Is there any way
to disable the Open button and force the user to save the file?  Or some
other trick to make sure the file saves as a type xls?

Response.Clear()

Response.Buffer = True

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

Response.Charset = ""

Response.AddHeader("Content-Disposition",
"attachment;filename=ClientAlertExport" & Now() & ".xls")

Dim SW As System.IO.StringWriter = New System.IO.StringWriter

Dim HTW As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(SW)

DataGrid1.RenderControl(HTW)

Response.Write(SW.ToString())

Response.End()

Thanks,

Ron
David Wier - 05 Jun 2007 16:52 GMT
It's because you're writing to the disk with HTML
check out this code sample:
http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=ExportDGExcel

Signature

David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

> Hi,
>
[quoted text clipped - 30 lines]
>
> Ron

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.