Posts

Showing posts from May, 2013

Design Patterns - Part 2 Builder Design Patterns

Image
Hi, Now I'm going to show you another Design pattern you can use for to software design problems you find again and again in real-world application development. This pattern is known as Builder Design Pattern Definition Separate the construction of a complex object from its representation so that the same construction process can create different representations. here is the sample code in c# Main Class  /// <summary> /// Main Class of the Application /// </summary> public class Program { /// <summary> /// Main Method of the Program /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Create director and builders var director = new Director(); Builder builderOne = new ConcreteBuilderOne(); Builder builderTwo = new ConcreteBuilderTwo(); // Construct two products dire...

How to Overcome Microsoft.Office.Interop.Excel errors in Visual Studio 2012

Image
When you are developing Excel Applications in visual Studio 2012 not sure about Visual studio 2010 (didn't have time to check on that) you will get some kind of harsh errors every developer don't want to see....Ha ha joking.. so when These error occurs I'm doing a simple trick to overcome those things. In the below I mention that trick in a step by step manner.  So these are the some of errors you will get when you build the application   To solve these kind of problems you can do various things. you can use Appropriate Application Interface to overcome some problems but when comes to the coding I'm bit lazy....ha ha joke  again.so What I'm doing is Go Project Properties and Change the Target FrameWork to 3.5 or low And remove System.Threading.Tasks namespace from your project. And Rebuild it...It should work smoothly. Hope This will help you.... See you soon.

Design Patterns - Part 1 Abstract Design Pattern

Image
Hello, Today I'm going to explain about something important to all the programmers....hmmm Design patterns...sound familiar? okay before going to the code level let's discuss about these design patterns. so basically design patterns are solutions to software design problems you find again and again in real-world application development. Patterns are about reusable designs and interactions of objects.            The 23 Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral. okay I'm not going to tell much and much boring stuff here. so let's go and learn design pattern one by one. Today I'm going to demonstrate about Abstract Factory Pattern Definition : Provide an interface for creating families of related or dependent objects without specifying their concrete classes. here is the sample code in c# Main Class /// <summary> ...

Dive Deep into XML Deserialization

Image
 I hope you guys read the previous article of mine. which i mentioned about the Advnance XML serialization mechanisms which you can use in your projects to overcome some recurring problems. so now I'm going to show you some generic methods which you can use to slove XML deserialization related problems. Actually I don't have lot of time to explain more about these functions but don't worry I added header comments and inline comment to explain the functionality of these code segments. If you want to know more please comment or message me. Have a nice day guys... see you soon.                         /// <summary> /// This method will convert (deserialize) XML file to a Object collection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="document">The document.</param> /// <param name="rootName">Name of the root.</param...

Dive deep into XML Serialization

Image
Today I'm going to show you some helper methods which will be help you to overcome some problems when you are dealing with XML Serialization.                            /// <summary> /// This method will convert given Object to a XML File /// </summary> /// <typeparam name="T">Type of the Object</typeparam> /// <param name="item">Object which is going to store in XML File</param> /// <param name="rootName">Put Root name if XML Root name is different from it's Original Name</param> /// <returns>XML document with object collection Data</returns> public static XmlDocument SerializeToXml<T>(T item, string rootName) { try { XmlSerializer serializer = null; serializer = string.IsNullOrEmpty(rootName) ? new XmlSerializer(typeof(T)) : new XmlSerializer...

Generic methods to serialize or Deserialize XML

Image
When you are working with XML files and C# Objects then you know about this serialization and deserialization thing. so today I'm not going to talk about the theory stuff regarding those concepts, rather than that I'm going to show you how to serialize or deserialize any given object or XML file using generic method. Happy coding.... and have a nice day...! /// <summary> /// Serialize object to XML File /// </summary> /// <typeparam name="T">Object Type</typeparam> /// <param name="value">Object contain Data</param> /// <param name="filename">XML File name and Path </param> public void Serialize<T>(T value,string filename) { try { XmlSerializer xmlserializer = new XmlSerializer(typeof(T)); Stream stream = new FileStream(filename, FileMode.Create); xmlserializer.Serialize(stream, v...

Open an excel File using C#

Image
Go to Visual studio and Create a new Console Application Project To work with Excel related functions you have to add a com object called Microsoft Excel 14.0 Object Library in my case I'm using visual studio 2008 so it may be diffrent to you. but most of cases the reference name is same Add following code segment to your Program.cs class and execute the program then you can see the newly created excel file on your Document folder. Happy coding. using System; using System.Data; using System.Data.SqlClient; using Excel = Microsoft.Office.Interop.Excel; namespace ExcelFile { /// <summary> /// Main Class /// </summary> class Program { /// <summary> /// Main Methods /// </summary> /// <param name="args">Event Arguements</param> static void Main(string[] args) { object misValue = System.Reflection.Missing.Value; var excelAp...