Generate your database entities using T4 templates

This post is about generating database entities using T4 templates. This code is pretty straight forward, you are reading the app.config to get the connection string, connecting to db server using Sql Server SMO objects, enumerating tables and columns. Here is the code, which will read the App.Config file and...


How to get text from Masked Text Box without the masked format

Today I saw some SO question asked about how to get values from Masked Textbox without the masked format. For those who don’t know what is masked textbox - Uses a mask to distinguish between proper and improper user input. Here is the code snippet. //Make sure user completed the...


How to Write a Visualizer in C#

Visualizers are components of the Visual Studio debugger user interface. A visualizer creates a dialog box or another interface to display a variable or object in a manner that is appropriate to its data type. For example, an HTML visualizer interprets an HTML string and displays the result as it...


CREATE DATABASE permission denied in database ‘master’ - SQL EXPRESS

Long back I wrote a post about Entity Framework Error – The underlying provider failed on Open. Yesterday some one told me, he is getting this error - CREATE DATABASE permission denied in database ‘master’, he is using an application pool with NETWORK SERVICE identity. Here is the solution, you...


How to set Bing wallpaper as your desktop wallpaper

This post is about setting Bing wallpaper as your desktop wallpaper using C# and Windows Forms. Bing.com is famous for having some nice pictures as wallpaper, updated on daily basis. The Bing Desktop application comes with same feature. Here is the code snippet, which has two parts one, download the...


How to upload file in ASP.Net MVC

This post is about upload file to server using ASP.Net MVC 4. First you need to modify the controller to accept the posted file along with the model. So you can modify it like this. [HttpPost] public ActionResult UploadImage(Student student, HttpPostedFileBase image) { var imageFile = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(image.FileName)); image.SaveAs(imageFile); return...


Problem with Internet Explorer and JSONResult in MVC

While working with the ASP.Net MVC project, one of my QA team member reported a strange issue, while uploading a file, Internet Explorer 9, showing a download file dialog like this. And the controller action is similar like this. [HttpPost, Authorize] public JsonResult Upload(FormCollection collection) { return Json("Uploaded successfully"); }...


How to integrate JQuery UI Datepicker in MVC

This post is about integrating JQuery UI DatePicker in MVC 4. First you need to modify the _layout.cshtml. Because by defualt, it won’t include required references for JQuery UI. You need to include both CSS and JS for JQuery UI references. So the modified _layout.cshtml will look like this. <!DOCTYPE...


Loading partial view on Ajax.Actionlink click

While working on an MVC project, I had to create few partial views and load them dynamically using Ajax. Here is the code snippet for the same. Controller method public ActionResult ShowMenu() { return PartialView("_SimpleMenu"); } In this I am returning the Partial View in the controller method. And here...


How to get code coverage in javascript

Long back I did some posts on getting code coverage in C#. And one of my previous posts was about implementing TDD in JavaScript. This post is about getting JavaScript code coverage. In computer science, code coverage is a measure used to describe the degree to which the source code...