How to read the version number from the assembly

by Edward 19 February 2011 16:15

I was recently working on a project where it was important to display the version number of the code on the page for testing purposes as well as making sure the correct set of code goes to production. If you don't use a build server, or just copy your code over to your hosting space, then the following might be of help. By using reflection you can get the major, minor, build, and revision numbers of the assembly and the display it on your web page, or use however you need too.

The following code sample will help you with getting the version number of your application.

        private static void Main(string[] args)
        {
            //Get Application version details
            ApplicationDetails applicationDetails = new ApplicationDetails();
            string versionNumber = applicationDetails.GetVersion();
        }  
    class ApplicationDetails
{
/// <summary>
/// Gets the version.
/// </summary>
public string GetVersion()
{
return GetType().Assembly.GetName().Version.ToString();
}

}

 

You can set the version number to auto increment, by setting it in the properties window of your application.

Tags: , ,

ASP.NET | Development Resources | Other

Visual Studio 2010 SP1 BETA Released

by Edward 10 January 2011 18:56

At the end of last year(December 2010), Microsoft released a service pack for Visual Studio 2010. The service pack is still in BETA mode, and therefore must be treated as any BETA software.... handle with care!

I was happy to hear there was a new service pack on it's way, which has some bug fixes and includes fixes for the text editor when coding javascript, css, and html. One bug I wanted to see fixed was the 'crash bug' where my editor seems to crash unexpectantly when working with older versions of the .net framework. Since the install I have not had any crashes, although I must state that I have not been working a lot over the December/January period!

Visual Studio 2010 logoOther key updates to look out for, is that VS2010 SP1 BETA allows the debugger to support IIS Express. The IntelliTrace now also supports Workflows and projects that use Web Parts. There's also support for unit testing targeting .Net 3.5,  and support for Visual C++, Visual Basic, SQL Server Compact 4.0 Design-Time, with enhancements for web deployment.

If you want to download SP1 BETA, you can find the download page here, but like I said - make sure you know the risks of installing BETA software!

Tags: , , ,

ASP.NET | Development Resources | Technology

Microsoft Offers Development Software at No Cost - for 3 years

by Edward 29 November 2010 21:44

Last year Scott Guthrie from Microsoft announced on his blog that Microsoft is launching a new program called 'Websitespark'. This program is designed for independent web developers and web development companies that build web applications and web sites on behalf of others.  It enables you to get software for FREE. What is the catch? A one-time $100 Program Offering Fee is due upon exit or upon the end of the 3 year term! I thought I would share this with you, to encourage you to register and download this software.

Once you have enrolled, you can access the following software.

  • For design, development, testing and demonstration of new websites – for a total of up to three users per Web design and development company:
    • Visual Studio Professional
    • Expression Studio (1 user) and Expression Web (up to 2 users)
    • Windows Web Server 2008 R2
    • SQL Server 2008 Web Edition
  • For production use – that is, to deploy and host new websites developed using Program software – using a total of up to four processors per Web design and development company, of the following (physical or virtual) dedicated servers:
    • Windows Web Server 2008 R2
    • SQL Server 2008 Web Edition
In addition to software, Microsoft WebsiteSpark offers Web development and design companies the opportunity to:
  • Get Business Opportunities: Get opportunities to expand your customer base and drive new business through showcasing your capabilities and connecting with partners, by featuring your talents in Microsoft marketing and business networking vehicles.
  • Get Support and Training - benefits include:
    • 2 professional support incidents
    • Online support through Managed newsgroups on MSDN is no longer available. Priority support is now provided in MSDN forums and other Microsoft online properties
    • Access to broad community support through connections with Network Partners, Hosting Partners and peers with complementary services and technologies

You can register for the program by visiting the Microsoft Websitespark portal.

Tags: , ,

Development Resources | Other | Technology

Generating XML Comments with GhostDoc

by Edward 20 July 2010 08:26

GhostDoc is a free Visual Studio extension which I stumbled accross while looking for something to help me with commenting my code. GhostDoc automatically generates XML documentation comments for methods and properties based on their type, parameters, name, and other contextual information. It takes the 'pain' out of commenting each method word for word - saving you time doing what you do best - coding!

Most documentation created will be a waste of time for a developer, and usually when there is no time to waste a developer might find the documentation is slowing him down. For any decent documentation to be useful, a developer must know that when the documentation was initially generated it was both correct and complete, it has also been updated as the project scope changed, or amendments was made to the code. I ofter find code to out of sync with documentation, which leaves me with lots of 'catch up' to do, before I feel in control and productive.

You can set it up, so when you right click on a method the "Document This" option becomes available that allows you to generate summary comments for your method.

GhostDoc comments

Here is an example of summary comments I created using this tool.       

        /// <summary>
        /// Checks for SQL injection.
        /// </summary>
        /// <param name="userInput">The user input.</param>
        /// <returns></returns>
        public static string checkForSQLInjection(string userInput)
        {
        // code here
       }

It is also supported in the following versions of the Visual Studio IDEs:

  • Visual Studio 2010
  • Visual Studio 2008
  • Visual Studio 2005

Supported Languages:

  • VB.NET
  • C#

Download it from here:

http://visualstudiogallery.msdn.microsoft.com/en-us/46A20578-F0D5-4B1E-B55D-F001A6345748

Tags: , ,

ASP.NET | Development Resources | Other

New Overload Method Available for String.Concat - available in .Net 4 Framework

by Edward 30 April 2010 16:57

A new feature I noticed while doing some prototyping some functionality with Visual Studio 2010, is the new overload method available for the 'String.Concat' method that takes an IEnumerable<T>. I found this to be very useful with LINQ query expressions.

Below is a simple example:

       

 public static void Main()
        {
            List<Employee> employees = new List<Employee>();

            employees.Add(new employees("John", "Doe"));
            employees.Add(new employees("Jane", "Doe"));
            employees.Add(new employees("John", "Code"));

            string output = String.Concat(employees.Where(employee =>
                          (employee.Surname == "Doe")));

            //write the output to screen
            Console.WriteLine(output);
        }


The Enumerable.Where extension method is called to extract the Employee objects whose 'Surname' property equals "Doe". The result is passed to the Concat<T>(IEnumerable<T>) method and displayed to the console.

 

Tags: , , , ,

ASP.NET | Development Resources

String.IsNullOrWhiteSpace - New method available in .NET Framework 4

by Edward 19 February 2010 14:11

String.IsNullOrWhiteSpace - New method available in .NET Framework 4

I found a very nice addition to the .NET Framework(version 4) while experimenting with code in Visual Studio 2010. There is a new method called "IsNullOrWhiteSpace", which is more powerful than the more familiar "IsNullOrEmpty" method. Incase you were wondering, the "IsNullOrEmpty" method is still available to be used.

For example, the common whitespace symbol " " represents a blank space, as used between words and sentences. The most common whitespace characters may be typed via the space bar or the Tab key. Depending on context, a line-break generated by the Return key (Enter key) may be considered whitespace as well. This brings concerns when using the "IsNullOrEmpty" method.

Introducing "IsNullOrWhiteSpace"! In the .NET Framework 4, string.IsNullOrWhiteSpace() will return true if a string is full of whitespace characters. I found this very helpful when dealing with getting XML data from external web services.

Here is a short example of how to use this new method.

   1:          static void Main(string[] args)
   2:          {
   3:              // set some test values
   4:              string[] testValues = { null, String.Empty, "ABCDE", 
   5:                            new String(' ', 20), "  	   ", 
   6:                            new String(' ', 10) };
   7:              //loop through the list and return result
   8:              foreach (string value in testValues)
   9:              {
  10:                  Console.WriteLine("Return is: " + 
  11:              String.IsNullOrWhiteSpace(value));
  12:              }
  13:              // we want to see the return
  14:              Console.ReadLine();
  15:          }

 

Tags: , , , ,

ASP.NET | Development Resources

Design Patterns 101 - The Abstract Factory Pattern

by Edward 31 January 2010 18:41

In my second article on design patterns, I am going to give you a quick overview of the "Abstract Factory pattern". Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

The Abstract Factory pattern is one level of abstraction higher than the factory pattern. One of the nice things about abstraction is that it lets you "take care" of the bigger picture and you only have to worry about the "details" later. The great advantage is that you are able to rely upon some other class to fill in the details for you.

You can use this pattern when you want to return one of several related classes of objects, each of which can return several different objects on request. In other words, the Abstract Factory is a factory object that returns one of several factories.

The code below demonstrates the Abstract Factory pattern creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code.

 

   1:  // Abstract Factory pattern - Structural example
   2:   
   3:  using System;
   4:   
   5:  namespace MyApp.AbstractFactory.Structural 
   6:  {
   7:      /// <summary>
   8:      /// MainApp startup class for Structural
   9:      /// Abstract Factory Design Pattern.
  10:      /// </summary>
  11:      internal class MainApp
  12:      {
  13:          /// <summary>
  14:          /// Entry point into console application.
  15:          /// </summary>
  16:          public static void Main()
  17:          {
  18:              // Abstract factory #1
  19:              AbstractFactory factory1 = new ConcreteFactory1();
  20:              Client client1 = new Client(factory1);
  21:              client1.Run();
  22:   
  23:              // Abstract factory #2
  24:              AbstractFactory factory2 = new ConcreteFactory2();
  25:              Client client2 = new Client(factory2);
  26:              client2.Run();
  27:   
  28:   
  29:              // Wait for user input
  30:              Console.ReadKey();
  31:          }
  32:      }
  33:   
  34:      /// <summary>
  35:      /// The 'AbstractFactory' abstract class
  36:      /// </summary>
  37:      internal abstract class AbstractFactory
  38:      {
  39:          public abstract AbstractProductA CreateProductA();
  40:          public abstract AbstractProductB CreateProductB();
  41:      }
  42:   
  43:      /// <summary>
  44:      /// The 'ConcreteFactory1' class
  45:      /// </summary>
  46:      internal class ConcreteFactory1 : AbstractFactory
  47:      {
  48:          public override AbstractProductA CreateProductA()
  49:          {
  50:              return new ProductA1();
  51:          }
  52:   
  53:          public override AbstractProductB CreateProductB()
  54:          {
  55:              return new ProductB1();
  56:          }
  57:      }
  58:   
  59:      /// <summary>
  60:      /// The 'ConcreteFactory2' class
  61:      /// </summary>
  62:      internal class ConcreteFactory2 : AbstractFactory
  63:      {
  64:          public override AbstractProductA CreateProductA()
  65:          {
  66:              return new ProductA2();
  67:          }
  68:   
  69:          public override AbstractProductB CreateProductB()
  70:          {
  71:              return new ProductB2();
  72:          }
  73:      }
  74:   
  75:      /// <summary>
  76:      /// The 'AbstractProductA' abstract class
  77:      /// </summary>
  78:      internal abstract class AbstractProductA
  79:      {
  80:      }
  81:   
  82:      /// <summary>
  83:      /// The 'AbstractProductB' abstract class
  84:      /// </summary>
  85:      internal abstract class AbstractProductB
  86:      {
  87:          public abstract void Interact(AbstractProductA a);
  88:      }
  89:   
  90:      /// <summary>
  91:      /// The 'ProductA1' class
  92:      /// </summary>
  93:      internal class ProductA1 : AbstractProductA
  94:      {
  95:      }
  96:   
  97:      /// <summary>
  98:      /// The 'ProductB1' class
  99:      /// </summary>
 100:      internal class ProductB1 : AbstractProductB
 101:      {
 102:          public override void Interact(AbstractProductA a)
 103:          {
 104:              Console.WriteLine(this.GetType().Name +
 105:                                " interacts with " + a.GetType().Name);
 106:          }
 107:      }
 108:   
 109:      /// <summary>
 110:      /// The 'ProductA2' class
 111:      /// </summary>
 112:      internal class ProductA2 : AbstractProductA
 113:      {
 114:      }
 115:   
 116:      /// <summary>
 117:      /// The 'ProductB2' class
 118:      /// </summary>
 119:      internal class ProductB2 : AbstractProductB
 120:      {
 121:          public override void Interact(AbstractProductA a)
 122:          {
 123:              Console.WriteLine(this.GetType().Name +
 124:                                " interacts with " + a.GetType().Name);
 125:          }
 126:      }
 127:   
 128:      /// <summary>
 129:      /// The 'Client' class. Interaction environment for the products.
 130:      /// </summary>
 131:      internal class Client
 132:      {
 133:          private AbstractProductA _abstractProductA;
 134:          private AbstractProductB _abstractProductB;
 135:          
 136:          // Constructor
 137:   
 138:          public Client(AbstractFactory factory)
 139:          {
 140:              _abstractProductB = factory.CreateProductB();
 141:              _abstractProductA = factory.CreateProductA();
 142:          }
 143:          
 144:          public void Run()
 145:          {
 146:              _abstractProductB.Interact(_abstractProductA);
 147:          }
 148:      }
 149:  }

Output:

ProductB1 interacts with ProductA1
ProductB2 interacts with ProductA2


The Usage of this pattern makes it possible to interchange concrete classes without changing the code that uses them, even at runtime! However, employment of this pattern, as with similar design patterns, may result in unnecessary complexity and extra work in the initial writing of code. Used correctly the "extra work" pays off in the second instance of using the Factory.

Tags: , ,

ASP.NET | Development Resources | Social Media

Design Patterns 101 - The Singleton Pattern

by Edward 29 January 2010 18:53

You probably heard of it, you probably don't even know that you are implementing it, but you need it on your resume! Once you start to use design patterns you will find that your code structure is improving. This is a "101" article about the simplest pattern - the Singleton pattern.

The purpose of this pattern is to ensure that a class has only one instance, and provide a global point of access to it. Any class in your application that has access to its namespace doesn't have to create or initialize the singleton. The caller can access properties and methods through the singleton's instance property. The singleton will retain state across calls.

   1:  // Singleton pattern - Structural example
   2:   
   3:  using System; 
   4:   
   5:  namespace MyApp.Singleton.Structural
   6:  {
   7:   
   8:    /// <summary>
   9:    /// MainApp startup class for Structural
  10:    /// Singleton Design Pattern.
  11:    /// </summary>
  12:   
  13:    class MainApp
  14:    {
  15:      /// <summary>
  16:      /// Entry point into console application.
  17:      /// </summary>
  18:   
  19:      static void Main()
  20:      {
  21:        // Constructor is protected -- cannot use new
  22:        Singleton s1 = Singleton.Instance();
  23:        Singleton s2 = Singleton.Instance(); 
  24:   
  25:        // Test for same instance
  26:        if (s1 == s2)
  27:        {
  28:          Console.WriteLine("Objects are the same instance");
  29:        }
  30:   
  31:        // Wait for user
  32:        Console.ReadKey();
  33:      }
  34:    }
  35:   
  36:    /// <summary>
  37:    /// The 'Singleton' class
  38:    /// </summary>
  39:   
  40:    class Singleton
  41:    {
  42:   
  43:      private static Singleton _instance;
  44:   
  45:      // Constructor is 'protected'
  46:      protected Singleton()
  47:      {
  48:      }
  49:   
  50:      public static Singleton Instance()
  51:      {
  52:        // Uses lazy initialization.
  53:        // Note: this is not thread safe.
  54:        if (_instance == null)
  55:        {
  56:          _instance = new Singleton();
  57:        }
  58:   
  59:   
  60:        return _instance;
  61:      }
  62:    }
  63:  }


Output:

Objects are the same instance

Note: The singleton pattern must be carefully constructed in multi-threaded applications. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one.

Tags: , , ,

ASP.NET | Development Resources | Social Media

Download Updated VS2010 and .NET 4 Training Kit

by Edward 12 January 2010 14:41

The updated VS2010 and .NET 4 Training Kit includes presentations, hands-on labs, and demos. Some of the features include:

  • C# 4.0
  • Visual Basic 10
  • F#
  • Parallel Extensions
  • Windows Communication Foundation
  • Windows Workflow
  • Windows Presentation Foundation
  • ASP.NET 4
  • Windows 7
  • Entity Framework
  • ADO.NET Data Services
  • Managed Extensibility Framework
  • Visual Studio Team System

You can download the training kit from the Microsoft website.

Come next month, Microsoft will offer testers yet another development milestone release of both Visual Studio 2010 and .NET Framework 4.

This version of the Training Kit works with Visual Studio 2010 Beta 2 and .NET Framework 4 Beta 2.

Tags: , , , ,

ASP.NET | Development Resources | Technology

What is ahead for .Net in 2010?

by Edward 29 November 2009 18:04

We are almost at the end of 2009, and this year there have been some interesting things happening in the world of .Net and Microsoft. There was the release of Silverlight 3, Internet Explorer 8, updates to the AJAX library and toolkit, and just over a month ago we got Windows 7.

I thought I would point out a few new .Net technologies to look out for next year.

  • Visual Studio 2010 and ASP.Net 4.0: Microsoft already released beta versions of Visual Studio 2010 that will be running the ASP.Net framework 4.0. They aim to release the newest edition of Visual Studio and ASP.Net 4.0 on 22 March 2010.
  • MVC Framework: The first version of this framework has been released in March 2009. Currently MVC 2.0 Beta is available for download. Microsoft has made several changes to this framework since the first release. You should find the latest version available for download in the first half of 2010.
  • JQuery: It has taken Microsoft a while to wake up, but it is nice to know that JQuery is being adopted by Visual Studio. JQuery is a Javascript library that has a lot of neat tools in it's bag.  It is very helpful for taking care of mundane tasks like "get that div" or "set that text box value."  It also has a great set of methods for dealing with AJAX.  
  • WCF, WF and WPF: ASP.Net is a maturing framework that will continue to move forward, with or without you. The best advice I have is to get on the wagon. Tools and accompanying frameworks are maturing in line, but behind, the .NET framework - your applications should be as well.  The earlier you start, the better. WCF, or known as Windows Communication Framework, is used to abstract the "plumbing" of your application. It can save you hours and hours of coding.
  • Silverlight 4.0: Microsoft Silverlight is a web application framework that provides functionalities similar to those in Adobe Flash, integrating multimedia, graphics, animations and interactivity into a single runtime environment. Silverlight 4.0 Beta has been released last month, so do not be surprised to see the latest version available before June 2010.

Tags: , , , , , , , ,

AJAX/JQuery | ASP.NET | Development Resources | Technology

About DasCode.Net

I'm a ASP.NET web developer and code enthusiast. Blogging about everything .Net related.

Code... that's .net

Month List