Friday, November 27, 2015

Export DataTable to Excel with Open XML in c#

This code sample will illustrate how we can create Excel file from a data table in c#. You will need to add DocumentFormat.OpenXml and WindowsBase dll references to make it work. private static void WriteExcelFile(string outputPath, DataTable table) { using (SpreadsheetDocument document = SpreadsheetDocument.Create(fileToGenerate, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookPart...

Wednesday, June 10, 2015

Configure StyleCop with MSBuild to treat Warnings as Errors

We can easily configure StyleCop with MSBuild to make warnings appear as errors with the help of StyleCop.MSBuild NuGet package. First go to Package Manager Console and install it with following command. Install-Package StyleCop.MSBuild Then unload your project and open the project file to modify...

Wednesday, April 22, 2015

MVC 5 with Unity for Dependency Injection

Dependency Injection allows us to inject objects into a class, instead of constructing them internally. Unity is a dependency injection container that we can use for constructor, property, and method call injections. You can get good idea about dependency injection by reading answers to this stack-overflow...