Showing all posts tagged: 'c#'

A 23-post collection

Checking if a generic collection is empty with Linq and C#

This is a common issue for many developers. How do you quickly and efficiently determine whether a given non-null collection contains any valid non-empty elements . The string class is cool because you can use the string.IsNullOrEmpty(yourstring); to test for null and/or empty. Unfortunately, generic collections don’t implement a similar method. There are two ways to deal with this. The first one requires you to write an extension for generic collections like this: public static bool IsEmpty<T>(this IEnumerable<T> list) { if (list is ICollection<T>) return ((ICollection<T& …[read more]


HTML5 Drag and Drop file upload with preview using jQuery and MVC 4

With the advent of HTML5 and its wide adoption by all major browsers, web developers now have a new arsenal in their hands for implementing powerful file upload functionality on their website. In this tutorial we will see how to implement this using the FileDrop jQuery plugin and an MVC controller to receive and store the uploaded files in a repository on the server. First create a new MVC 4 website in Visual Studio. An existing website can also be used.  Create a new blank view and name it “UploadFiles”. You should be able to navigate to the page using …[read more]


NLog with SQL Server and MVC 4

NLog is a great open-source logging tool that allows developers to easily and efficiently implement custom logging. Nlog can be configured to log to a number of targets, but on this tutorial we will be looking at logging to the database. First you need to add NLog to your MVC website. Bring up the Nuget package manager and search for NLog. Add the following packages: NLog NLog Schema for Intellisense NLog configuration NLog for Extended Profile This will add the necessary dlls and config files for use later. Once the installation is complete, you should see the following file at …[read more]


jQuery UI Autocomplete with jSON in MVC 4

jQueryUi has an autocomplete plugin that allows developers to turn any standard text box to turn any standard textbox to an autocomplete search box. In this case we will try to implement this in the simplest way possible using a web service as the data source. First of all, create a standard MVC 4 project. This will be used to test our functionality, however any existing website can be used for the same purpose. If you are not already referencing the jQuery and jQuery UI libraries in your _layout.cshtml, add them. You can either add them directly in your …[read more]


Mutliple object definition files with Spring.Net

Spring.Net is a great IoC (Inversion of Control) framework that allows developers to implement Dependency Injection using an xml configuration. In most cases, the Spring config will end up in either your app/ web.config files. However, in some cases, it may be desirable or necessary to keep the Spring object definitions outside your app/web.config files in order to be able to share them across multiple projects, eg your website and your unit tests. The Spring.Net framework has a feature to allows us to do this easily, but there are a few caveats that I will …[read more]


Using an Smtp client in ASP.NET MVC 4 and C#

If you need to send emails from your website, the .NET framework provides a very handy library for this:  System.Net.Mail. The configuration and testing is pretty straightforward so let’s get started. Firstly we need to configure the SMTP settings in the web.config. Under the <configuration> element add the following config section: <system.net> <mailSettings> <!-- Method#1: Send emails over the network --> <smtp deliveryMethod="Network" from="[email protected]"> <network host="your_smpt_server_dns_name" userName="your_smpt_server_username" password="your_smpt_ …[read more]


Editing xml files with Advanced Installer

As part of my #learn365 today I will post a new feature I've learned about the Advanced Installer application. Advanced Installer, for those who never heard it before, is equivalent to InstallShield and allows users to create powerful custom installers for a variety of apps. So today’s lesson is: How to edit xml files and keep them up-to-date with the repo. The problem in my scenario is that I have to edit the sql connection strings in all the app and web config files using the values supplied by the user during the installation. There are a number of …[read more]