Export To Excel Data By LINQ to SQLThere are many times we require certain reports to be exported to certain require Files i. Export to Excel, PDF and CSV but for today we can see how we can export to excel with querying to database through LINQ to SQL query. So lets start to build interface buttons which will do the rest of work to query and export to excel. Button IDbtn. Get. Data runatserver TextExport to Excel On. Clickbtn. Get. DataClick This button has On. Click btn. Get. DataClick Event which will fire when we click on it, before starting we will add the following references to the project. Reference folder of solution. System. Web using System. Drawing using System. The Leadership Of Muhammad Pdf Converter' title='The Leadership Of Muhammad Pdf Converter' />Reflection using System. Data using System. Linq using Office. Open. Xml using Office. Open. Xml. Style using Office. Open. Xml. Table Now we will write the backend logic of button. Get. DataClickobject sender, Event. Args e Data. Table dt new Data. Table Listlt News. Feed News. Feeds from emp in db. News. Feed select emp. To. Listlt News. Feed if News. There are many times we require certain reports to be exported to certain require Files i. Export to Excel, PDF and CSV but for today we can see how we can export to. Feeds. Any Listto. Data. Table. Converter converter new Listto. Data. Table. Converter dt converter. To. Data. TableNews. Feeds Export. Exceldt Now I will explain the line of code as you can see we have a button event which will fire on click. FIrst of all we create Data. Table and initialize it on the start which will hold the converted data. Data. Table dt new Data. Table Now we have write the linq to sql query and all the result which will fetch through query is moved to the list. Listlt News. Feed News. Feeds from emp in db. News. Feed select emp. To. Listlt News. Feed After that we will check as a best practice, is there any data returned by the query by writing line of code like this. If list variable contains any thing we have use. Any as a best practice to check the content length otherwise you can use. Count method too to check for any count of returned row to do the rest of processing. News. Feeds. Count Now we will create new class and initialize it to convert the list structure to datatable to ease our work as per our requirement. Listto. Data. Table. Converter converter new Listto. Data. Table. Converter Complete class is elaborated below. Listto. Data. Table. Converter public Data. Table To. Data. Tablelt T Listlt T items Data. Table data. Table new Data. TabletypeofT. Name Property. Info Props typeofT. Get. PropertiesBinding. Flags. Public Binding. Flags. Instance foreach Property. Info prop in Props data. Table. Columns. Addprop. The Leadership Of Muhammad Pdf Converter' title='The Leadership Of Muhammad Pdf Converter' />BibMe Free Bibliography Citation Maker MLA, APA, Chicago, Harvard. We provide excellent essay writing service 247. Enjoy proficient essay writing and custom writing services provided by professional academic writers. Name foreach T item in items var values new objectProps. Length for int i 0 i lt Props. Length i valuesi Propsi. Get. Valueitem, null data. Table. Rows. Addvalues return data. Table I have elaborate every piece of code with comments what is going on while converting list to data. Table. We are using the Data. Table method to convert it to the datatable from list inside class Listto. Data. Table. Converter. To. Data. TableNews. Feeds Finally, we will use the Export to Excel function by allocating the content type to convert it to the appropriate format. We will call export method and pass converted data. Table from list. For conversion to excel purpose I am using microsoft built in library called open office XML Extension. Right click on References folder of project and select Add Reference. Add below highlighted Extensions in to the project. Add This Method to File. Export. ExcelData. Table dt using Excel. Package pck new Excel. Package Excel. Disk Drill Pro 2.0 Activation Code. Worksheet ws pck. Workbook. Worksheets. AddExport. Report ws. CellsA1. Load. From. Data. Tabledt, true, Table. Styles. Medium. 15 Byte file. Bytes pck. Get. As. Byte. Array Http. Context. Current. Response. Clear. Content Http. Context. Current. Response. Add. Headercontent disposition,attachment filenameExported Date. Time. Now. To. StringMddyyyyHMs . Http. Context. Current. Response. Content. Type applicationvnd. Http. Context. Current. Response. Binary. Writefile. Bytes Http. Context. Current. Response. End Code Elaboration Excel. Worksheet ws pck. Workbook. Worksheets. AddExport. Report ws. CellsA1. Load. From. Data. Tabledt, true, Table. Styles. Medium. 15 Byte file. Bytes pck. Get. As. Byte. Array Http. Context. Current. Response. Add. Headercontent disposition, attachment filenameExported Date. Time. Now. To. StringMddyyyyHMs . Http. Context. Current. Response. Content. Type applicationvnd. Http. Context. Current. Response. Binary. Writefile. Bytes Http. Context. Current. Response. End Final Output.