Avatar of sharepoint0520
sharepoint0520

asked on 

Best and fast way to export to excel by c# code in Sharepoint 2010 ?

Hi,

  We have sharepoint 2010 and we have developed custom web part where we export sharepointlist to excel by some dynamic filter. We first load to datatable and bind gridview and from gridview we export. We have large list which has more than 50000 records.

Do we have another way or quick way to export to excel by custom web part ?
Microsoft SharePoint.NET ProgrammingC#

Avatar of undefined
Last Comment
sharepoint0520
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

It would probably be quicker to run a CAML query and write the output from that directly to file.

e.g.: https://msdn.microsoft.com/en-us/library/office/ee534956%28v=office.14%29.aspx

The only issue is CAML is a bit of a pain, so use a tool such as CAML Designer to build your query, then use that in your code.

Another alternative is to use SSIS to extract Sharpeoint List data to a database, then extract or report on whatever you need from that.  I've done that successfully on SP2010 and its pretty easy to do if you know SSIS.  The advantage of this is if you have regular reporting requirements it's straightforward to schedule a package and rebuild reports and data overnight for example in a data warehousing scenario.
Avatar of sharepoint0520
sharepoint0520

ASKER

Hi,

 I can use to CAML query to grab data but my question was to export to excel very quickly with good performance.
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

Use CAML to grab the data, iterate over the resultset, and write it to a flat .csv file usng FileIO.  This will remove all the overhead of binding to a gridview.
Avatar of sharepoint0520
sharepoint0520

ASKER

Hi,

 Do we have any sample code or example to write it to flat .csv ?
ASKER CERTIFIED SOLUTION
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

If you don't like that then as I say you could use a report in SSRS to extract the data.  I think modern versions of this allow querying SharePoint lists as a datasource, although I have never done this:
https://msdn.microsoft.com/en-us/library/ee633650.aspx

This is a code free solution, and you could even use the report scheduler to to run this every day and email it to you for example.  You can extract to Excel from the report viewer front end.
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi,
from another question I answered a couple of days ago I found a really neat JavaScript library which can create Excel files in JavaScript.

The open source project can be found here:
https://github.com/stephenliberty/excel-builder.js/tree/master

Unfortunately their main web site has currently some issues, but using Google Search and there the cached site, you still can get an idea how to use.
You simply have to pass the data Array, but you can also manipulate data types, create multiple Sheets in one workbook ...

I will definitly use it in further projects.

HTH
Rainer
Avatar of sharepoint0520

ASKER

Thanks
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo