Solved

Export Dataset to Excel

Posted on 2007-04-05
4
616 Views
Last Modified: 2012-06-27
I use the following script to export dataset to excel

Public Class DataSetToExcel

  Public Shared Sub Convert(ByVal ds As DataSet, ByVal response As HttpResponse)
    'first let's clean up the response.object
    response.Clear()
    response.Charset = ""
    'set the response mime type for excel
    response.ContentType = "application/vnd.ms-excel"
    'create a string writer
    Dim stringWrite As New System.IO.StringWriter
    'create an htmltextwriter which uses the stringwriter
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
    'instantiate a datagrid
    Dim dg As New DataGrid
    'set the datagrid datasource to the dataset passed in
    dg.DataSource = ds.Tables(0)
    'bind the datagrid
    dg.DataBind()
    'tell the datagrid to render itself to our htmltextwriter
    dg.RenderControl(htmlWrite)
    'all that's left is to output the html
    response.Write(stringWrite.ToString)
    response.End()
  End Sub
End Class

It has been working fine except now that I move the script to a new SharePoint server, it stops working.  Instead of exporting the dataset to an excel, it displays the XML on the screen.  Help.  

0
Comment
Question by:chaochenga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 18856444
Response.Write writes things to the response stream. That usually means it will be displayed on the screen. However, if the client does not know how to handle the fille type it will try to save it. When you installed Sharepoint you probably set IE to recognise xls files so that they could be displayed. If this is the case then changin the line response.ContentType = "application/vnd.ms-excel" will stop it from happening.
 
0
 

Author Comment

by:chaochenga
ID: 18857355
What do I need to change the line response.ContentType = "application/vnd.ms-excel" to?
0
 

Author Comment

by:chaochenga
ID: 18857826
I removed the line response.ContentType = "application/vnd.ms-excel" and it is now showing data on the screen.  However, I need the save as dialog to pop up.  Help.
0
 

Author Comment

by:chaochenga
ID: 18858049
I got it to work with the following

Response.AppendHeader( "content-disposition",  "attachment; filename=" + name )
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question