Posts

Showing posts with the label .Net4.5

Updating MVC4 to MVC5

 In my last article on MVC, I updated Razor 2.0 to 3.0 and showed the difficulties of updating the Razor nuget package in a MVC application. This article picks up from there and since Razor 3.0 is dependent on MVC5 I can assume you have updated Razor already. Typical errors you will see.. Method not found: 'System.Web.WebPages.IDisplayMode System.Web.Mvc.ControllerContext.get_DisplayMode()'. Description:  An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:  System.MissingMethodException: Method not found: 'System.Web.WebPages.IDisplayMode System.Web.Mvc.ControllerContext.get_DisplayMode()'. Updating the  System.Web.WebPages to version 3.0 fixed this issue. However you may see more packages issues like it. What you can do is try reinstall each package that appears to be broken like so.. Update-Package –reins

MVC Excel Email Attachment with NPOI

    The First Question I had after successfully creating a Excel sheet was  how do I create an attachment from a stream?  A second to be more specific was  how do I add an attachment to an email using System.Net.Mail?  Ultimately I wanted to have the  Excel Exports in C# using NPOI  but I started small and thankfully others had already asked and answered these questions. After which was just a matter of knowing  What the correct content-type for excel files was? First Attempt MailMessage mail = new MailMessage(); HSSFWorkbook workbook = CreateExcel(OrderId); MemoryStream ms = new MemoryStream(workbook.GetBytes()); mail.Attachments.Add(new Attachment(ms, "example.xls", "application/vnd.ms-excel")); _emailService.SendEmail("example@example.com", "Email test", "Testing 123"); Changed it to.. MemoryStream ms = new MemoryStream(); workbook.Write(ms); This was based on the QA " NPOI -

MVC Data Exported to Excel with NPOI

This is an article for just writing an Excel file using  NPOI  and I want the quickest and easiest way to export a excel file from Asp.net MVC. To keep everything in work fluid motion I will keep the user on the same page and do a forced download within that page. This is a setup that I have seen in multiple times and I think works great in today's modern website designs. Creates excel files Leniel Macaferi's blog: Creating Excel spreadsheets .XLS and .XLSX in C# Create Excel Spreadsheets Using NPOI var workbook = new HSSFWorkbook(); var ExampleSheet = workbook.CreateSheet("Example Sheet"); var rowIndex = 0; var row = ExampleSheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue("Example in first cell(0,0)"); rowIndex++; Problems I faced XLS is not the same as CVS which is obvious but truthfully I did not know the difference between the two file types (other than their different extensions). So I asked myself what is the  Difference between CS

Asp.net MVC4 - Bundling and Minification

    While this article may be very simple and  straightforward,  there are a few concepts here I think are important to note . In my next article will be looking more in depth on the idea of creating a customized Web.config, but for now with this article, I just want to look at activating the bundling and minification feature by using the xml tags inside a MVC's Web.config. This feature is only available i n ASP.NET 4.5  and above. The First Problem With the following inside your Web.config... (transform is with a Captial T.) And with either of the following inside your build config or customized Web.config (I.E. Web.Release.config) This also can be achieved by doing the following...      In both snippets of code you do not need to use the "xdt:Locator" attribute (used only in cases where there are multiples elements of the same name .   What you may not see is that in the Web.config we have the "location" tag