<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1361326064122483419</id><updated>2012-01-11T12:42:00.665+05:30</updated><category term='C#'/><category term='Binary stream to Image'/><category term='LINQ'/><category term='ASP.NET 2.0'/><category term='javascript'/><category term='Events and Delegates'/><category term='DotNetNuke'/><category term='GroupBy'/><category term='MSMQ'/><category term='XML'/><category term='WPF WinForm Interoperability'/><category term='WPF'/><category term='Serialization'/><title type='text'>new Developer(); in the &lt;kitchen/&gt;</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-1060759575623535430</id><published>2011-12-22T17:42:00.000+05:30</published><updated>2012-01-03T15:00:22.281+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='GroupBy'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>C# LINQ To Objects: Using GroupBy with more control</title><content type='html'>&lt;p&gt;The &lt;a href="http://www.arpitkhandelwal.com/2011/10/grouping-in-linq-c.html"&gt;previous post&lt;/a&gt; demonstrated simple use of GroupBy to collect aggregates on some property of an object. This post will demonstrate an example of another overload of GroupBy method which will allow us to group the objects in a more flexible way.&lt;/p&gt;&lt;p&gt;For this example too, we will use the same List of Score objects, which we used in  &lt;a href="http://www.arpitkhandelwal.com/2011/10/grouping-in-linq-c.html"&gt;previous example&lt;/a&gt;. However, the objective of grouping will be quite different now.&lt;p&gt; So, the objective is to retrieve a table of subject-wise highest scores and name of students who attained this highest score in corresponding subject. The structure of output can be visualized as below-&lt;br/&gt;&lt;table width="500px" align-text="center"&gt; &lt;tr &gt;  &lt;th style="border: 1px solid #000000; width:150px"&gt;Subject&lt;/th&gt;  &lt;th style="border: 1px solid #000000; width:150px"&gt;Top Score&lt;/th&gt;  &lt;th style="border: 1px solid #000000; width:200px"&gt;Top Scorer's Name&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt;  &lt;td style="border: 1px solid #000000; height: 20px"&gt;&lt;/td&gt;  &lt;td style="border: 1px solid #000000"&gt;&lt;/td&gt;  &lt;td style="border: 1px solid #000000"&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/table&gt;&lt;p&gt;To achieve this form of grouping, we will need to use the GroupBy method in such a way that it allows us to define what form of result we need as an output of grouping. One of the eight overloads of GroupBy extension method provides a flexibility to define the result type as an argument to itself. Below is the overload we are looking for-&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;public static IEnumerable&amp;lt;IGrouping&amp;lt;TKey, TSource&amp;gt;&amp;gt; GroupBy&amp;lt;TSource, TKey, TElement, TResult&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, TKey&amp;gt; keySelector,&lt;br /&gt;    Func&lt;TSource, TElement&gt; elementSelector, &lt;br /&gt;    Func&amp;lt;TKey, IEnumerable&amp;lt;TSource&amp;gt;, TResult&amp;gt; resultSelector) &lt;br /&gt;&lt;/pre&gt;Here are the various arguments and their meanings:&lt;p&gt;The first argument &lt;i&gt;this IEnumerable&amp;lt;TSource&amp;gt; source&lt;/i&gt; is the input sequence itself and as it is an extension method, the first argument is never actually passed into the method. &lt;/p&gt;&lt;p&gt; The second argument &lt;i&gt;Func&amp;lt;TSource, TKey&amp;gt; keySelector&lt;/i&gt;, is a delegate to apply to each element in the input sequence to obtain a key (type TKey). The key is what decides which group the element is associated with. We want our final output to be grouped on SubjectName property of Score object. So, our obvious choice as keySelector will be-&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;groupingKey =&gt; groupingKeySubjectName, //keySelector&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The third argument &lt;i&gt;Func&lt;TSource, TElement&gt; elementSelector&lt;/i&gt; is a delegate to apply to each element (type TElement) to obtain the value which should be part of the relevant group. Once we have grouped our list by SubjectName, we will need to identify the students with their marks in each group.&lt;/p&gt;&lt;p&gt; So, as an element selector we create an anonymous type with properties Name and Marks&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;elementSelector =&gt; new { Name = elementSelector.StudentName, Marks = elementSelector.MarksObtained },   //elementSelector &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now the last argument &lt;i&gt;Func&amp;lt;TKey, IEnumerable&amp;lt;TSource&amp;gt;, TResult&amp;gt; resultSelector)&lt;/i&gt;, is a delegate to apply to each grouping to produce a final result (type TResult). As an output, we want a sequence of objects with properties having subject name, highest scores and name of student who attained highest score.&lt;/p&gt;&lt;p&gt; So, we create another anonymous type with properties SubjectName, HighestScore and HighestScorerName. SubjectName will be same as the key of grouping operation. HighestScore of a subject can be determined from elementSelector of the corresponding group and HighestScorerName is the Name of student who has Marks equal to HighestScore. So, here is how our resultSelector will look like-&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;(groupingKey, elementSelector) =&gt; new { //resultSelector&lt;br /&gt;                SubjectName = groupingKey,&lt;br /&gt;                HighestScore = elementSelector.Max(t =&gt; t.Marks),&lt;br /&gt;                HighestScorerName = elementSelector.Where(t =&gt; t.Marks == elementSelector.Max(f =&gt; f.Marks)).Select(t =&gt; t.Name).SingleOrDefault()}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;This is it. Lets assemble the GroupBy method on the instance of List&lt;Score&gt; from &lt;a href="http://www.arpitkhandelwal.com/2011/10/grouping-in-linq-c.html"&gt;previous example&lt;/a&gt; and see what we get&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;var topScorers = examResult.GroupBy(&lt;br /&gt;            groupingKey =&gt; groupingKey.SubjectName, //keySelector&lt;br /&gt;            elementSelector =&gt; new { Name = elementSelector.StudentName, Marks = elementSelector.MarksObtained },   //elementSelector &lt;br /&gt;            (groupingKey, elementSelector) =&gt; new { //resultSelector&lt;br /&gt;                SubjectName = groupingKey,&lt;br /&gt;                HighestScore = elementSelector.Max(t =&gt; t.Marks),&lt;br /&gt;                HighestScorerName = elementSelector.Where(t =&gt; t.Marks == elementSelector.Max(f =&gt; f.Marks)).Select(t =&gt; t.Name).SingleOrDefault()&lt;br /&gt;            }).Select(resultSelector =&gt; resultSelector).ToList();&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;When you look at the output sequence, notice that this overload of GroupBy does not return the IEnumerable of IGrouping&lt;String,Score&gt; type but it returns the IEnumerable of anonymous type defined in the third parameter (resultSelector) of the GroupBy method. This is all the fun of it.&lt;/p&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://arpit.6te.net/Images/groupby.jpg" imageanchor="1" style=""&gt;&lt;img border="0" height="342" width="677" src="http://arpit.6te.net/Images/groupby.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-1060759575623535430?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/1060759575623535430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2011/12/c-linq-to-objects-using-groupby-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/1060759575623535430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/1060759575623535430'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2011/12/c-linq-to-objects-using-groupby-with.html' title='C# LINQ To Objects: Using GroupBy with more control'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-3800913636180179472</id><published>2011-10-22T09:27:00.000+05:30</published><updated>2012-01-03T15:01:50.555+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='GroupBy'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>C# LINQ To Objects: Simple Grouping using GroupBy</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;/div&gt;We face number of scenarios in day to day programming when we need to group a number of records based on a key and calculate aggregates like SUM, AVG, MAX, MIN etc on these groups. We do it more frequently in SQL but we can also do it easily in C# using LINQ.&lt;br /&gt;&lt;br /&gt;Static class Enumerable in System.Linq namespace defines an extension method- GroupBy with one (simpletest) of the available overloads&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;public static IEnumerable&amp;lt;IGrouping&amp;lt;TKey, TSource&amp;gt;&amp;gt; GroupBy&amp;lt;TSource, TKey&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, TKey&amp;gt; keySelector) &lt;br /&gt;&lt;/pre&gt;This method does to an IEnumerable exactly what GROUP BY in SQL does to a number of records. Lets explore it by means of an example. First we need a class on IEnumerable of which we can apply GroupBy method.&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;public class Score {&lt;br /&gt;    public string StudentName { get; set; }&lt;br /&gt;    public string SubjectName { get; set; }&lt;br /&gt;    public float MaxMarks { get; set; }&lt;br /&gt;    public float MarksObtained { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Class Score is a simple class which represents score of a student in a particular subject. There are two float type properties MaxMarks and MarksObtained. These two properties can be used to calculate aggregate on. Lets suppose we have a collection of objects of Score type, each represents the score of a student in a subject and we need to calculate Average marks obtained for students in a particular subject.&lt;br /&gt;Lets first create a list of Score objects&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;class Program {&lt;br /&gt;    static void Main(string[] args) {&lt;br /&gt;        List&amp;lt;Score&amp;gt; examResult = new List&amp;lt;Score&amp;gt;();&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Steve", SubjectName = "Maths", MaxMarks = 100, MarksObtained = 90 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Steve", SubjectName = "Physics", MaxMarks = 100, MarksObtained = 86 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Steve", SubjectName = "Chemistry", MaxMarks = 100, MarksObtained = 72 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Steve", SubjectName = "Computer Science", MaxMarks = 100, MarksObtained = 91 });&lt;br /&gt;&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Sarah", SubjectName = "Maths", MaxMarks = 100, MarksObtained = 85 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Sarah", SubjectName = "Physics", MaxMarks = 100, MarksObtained = 76 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Sarah", SubjectName = "Chemistry", MaxMarks = 100, MarksObtained = 92 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "Sarah", SubjectName = "Computer Science", MaxMarks = 100, MarksObtained = 92 });&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        examResult.Add(new Score() { StudentName = "David", SubjectName = "Maths", MaxMarks = 100, MarksObtained = 74 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "David", SubjectName = "Physics", MaxMarks = 100, MarksObtained = 82 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "David", SubjectName = "Chemistry", MaxMarks = 100, MarksObtained = 85 });&lt;br /&gt;        examResult.Add(new Score() { StudentName = "David", SubjectName = "Computer Science", MaxMarks = 100, MarksObtained = 89 });&lt;br /&gt;&lt;br /&gt;        Console.ReadLine();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Now we have is a list of type Score having 12 objects of Score for 3 students and 4 subjects and we are all set to determine the average marks obtained by these students in each subject. So, our key to group these records should be SubjectName property and we want to calculate average on MarksObtained property. Here is how it is done-&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;var avgResults = examResult.GroupBy(rec =&amp;gt; rec.SubjectName).&lt;br /&gt;            Select(rec =&amp;gt; new { SubjectName = rec.Key, AVGMarks = rec.Average(t =&amp;gt; t.MarksObtained) }).ToList();&lt;br /&gt;&lt;br /&gt;foreach (var item in avgResults) {&lt;br /&gt;     Console.WriteLine("Subject Name: {0},   Average Marks:{1}", item.SubjectName, item.AVGMarks);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Notice that in Select method, we create an Anonymous type with two properties SubjectName and AVGMarks. Finally we get a collection (avgResults) of this Anonymous type.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-3800913636180179472?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/3800913636180179472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2011/10/grouping-in-linq-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/3800913636180179472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/3800913636180179472'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2011/10/grouping-in-linq-c.html' title='C# LINQ To Objects: Simple Grouping using GroupBy'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-7341927065546361382</id><published>2011-10-16T22:28:00.000+05:30</published><updated>2012-01-03T15:00:09.577+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Serialization'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Serializing .NET Classes into XML (C#)</title><content type='html'>&lt;b&gt;Serialization:&lt;/b&gt;&amp;nbsp;The process of converting an object into a stream of bytes. This stream of bytes can be persisted in form of a physical file like XML.&lt;br /&gt;In .NET framework, the namespace &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.aspx"&gt;System.Xml.Serialization&lt;/a&gt; provides all the necessary functionality to help convert a "Serializable" object into stream of bytes and then &lt;a href="http://msdn.microsoft.com/en-us/library/gg145019.aspx"&gt;System.IO&lt;/a&gt; helps with all the necessary tools to write those stream of bytes into a physical file.&lt;br/&gt;Here is an example where we serialize an object into a stream and then save the stream into a physical XML&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Model classes&lt;/b&gt;: First we will create a few simple classes which we want to be represented in form of an XML&lt;br /&gt;&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;public class University {&lt;br /&gt; public University() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public short Rating { get; set; }&lt;br /&gt;    public List&amp;lt;Institute&amp;gt; AffiliatedInstitutes = new List&amp;lt;Institute&amp;gt;();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Institute {&lt;br /&gt; public Institute() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public short Rating { get; set; }&lt;br /&gt;    public List&amp;lt;Student&amp;gt; Students = new List&amp;lt;Student&amp;gt;();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;public class Course {&lt;br /&gt;    public Course() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public short DurationInMonths { get; set; }&lt;br /&gt;    public string CourseType { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Student {&lt;br /&gt;    public Student() { }&lt;br /&gt;&lt;br /&gt;    public string FirstName { get; set; }&lt;br /&gt;    public string LastName { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public string EnrollmentNumber { get; set; }&lt;br /&gt;    public Course Course { get; set; }&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;In the example above, we are going to serialize the class University which must include properties of all the types (Institute, Course, Student). To enable these classes to be serialized we need to decorate them with some attributes. Lets take a look at the definitions of same classes- &lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;using System.Collections.Generic;&lt;br /&gt;using System.Xml.Serialization;&lt;br /&gt;using System.IO;&lt;br /&gt;using System;&lt;br /&gt;...&lt;br /&gt;[XmlRoot()]&lt;br /&gt;public class University {&lt;br /&gt; public University() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public short Rating { get; set; }&lt;br /&gt;    public List&amp;lt;Institute&amp;gt; AffiliatedInstitutes = new List&amp;lt;Institute&amp;gt;();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[XmlInclude(typeof(Institute))]&lt;br /&gt;public class Institute {&lt;br /&gt; public Institute() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public short Rating { get; set; }&lt;br /&gt;    public List&amp;lt;Student&amp;gt; Students = new List&amp;lt;Student&amp;gt;();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;[XmlInclude(typeof(Course))]&lt;br /&gt;public class Course {&lt;br /&gt;    public Course() { }&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public short DurationInMonths { get; set; }&lt;br /&gt;    public string CourseType { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[XmlInclude(typeof(Student))]&lt;br /&gt;public class Student {&lt;br /&gt;    public Student() { }&lt;br /&gt;&lt;br /&gt;    public string FirstName { get; set; }&lt;br /&gt;    public string LastName { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public string EnrollmentNumber { get; set; }&lt;br /&gt;    public Course Course { get; set; }&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the class definitions above, there are a few things worth noticing.&lt;br/&gt;&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlroot.aspx"&gt;XmlRoot()&lt;/a&gt;&lt;/b&gt; attribute: The class definition following this attribute is chosen to be the root node of the finally serialized XML. &lt;br/&gt;&lt;b&gt;&lt;a href=""&gt;XmlInclude(TYPE)&lt;/a&gt;&lt;/b&gt; attribute: The class definitions following this attribute are marked to be serialized, if there exist any class member of its type in the root object.&lt;br/&gt;By default all the unmarked properties of a class are treated as child elements of parent object(XmlElement). If we want a property to appear like an attribute of its parent node, we need to add an attribute &lt;b&gt;XmlAttribute("attributeName")&lt;/b&gt;.&lt;br/&gt;Finally we define a method in our University class which actually does the job to convert an object of its own type into stream of bytes (i.e. serializes its object) and then writes those stream of bytes to a physical fine.&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;&lt;br /&gt;public class University {&lt;br /&gt;    public University() {}&lt;br /&gt;&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;    public string Address { get; set; }&lt;br /&gt;    public short Rating { get; set; }&lt;br /&gt;    public List&amp;lt;Institute&amp;gt; AffiliatedInstitutes = new List&amp;lt;Institute&amp;gt;();&lt;br /&gt;&lt;br /&gt;    public bool SaveToXML(string filePath) {&lt;br /&gt;  try {&lt;br /&gt;   //Instantiate an object of XmlSerializer class specifying the root object type (i.e. University)&lt;br /&gt;   XmlSerializer serializer = new XmlSerializer(typeof(University));&lt;br /&gt;   &lt;br /&gt;            //Instantiate an object of memory stream which we will use as a continer for the serialized stream&lt;br /&gt;   MemoryStream ms = new MemoryStream();&lt;br /&gt;&lt;br /&gt;            using (ms) {&lt;br /&gt;                //Run Serialize method on current instance of University class&lt;br /&gt;    serializer.Serialize(ms, this);&lt;br /&gt;    &lt;br /&gt;    //Read the memory stream into a string object, &lt;br /&gt;    //though we don't need to read it but we will do so, so that we can debug it and see the XML first before we write it&lt;br /&gt;                ms.Position = 0;&lt;br /&gt;    string data = string.Empty;&lt;br /&gt;    StreamReader reader = new StreamReader((Stream) ms);&lt;br /&gt;                using (reader) {&lt;br /&gt;     data = reader.ReadToEnd();&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;    //Now write the string to the specified path&lt;br /&gt;                File.WriteAllText(filePath, data);&lt;br /&gt;    reader.Dispose();&lt;br /&gt;    return true;&lt;br /&gt;            }&lt;br /&gt;        } catch (Exception) {&lt;br /&gt;            return false;&lt;br /&gt;  }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now, lets test the code above-&lt;br /&gt;&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;      &lt;br /&gt;static void Main(string[] args) {&lt;br /&gt; Course mastersBusiness = new Course() {&lt;br /&gt;  CourseType = "PG-Degree",&lt;br /&gt;        DurationInMonths = 24,&lt;br /&gt;        Name = "Masters of Business Administration"&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    Course bachelorEngineering = new Course() {&lt;br /&gt;        CourseType = "Graguate-Degree",&lt;br /&gt;        DurationInMonths = 48,&lt;br /&gt;        Name = "Bachelor of Engineering"&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    Student steveRichards = new Student() {&lt;br /&gt;        FirstName = "Steve",&lt;br /&gt;        LastName = "Richards",&lt;br /&gt;        Course = bachelorEngineering,&lt;br /&gt;        Address = string.Empty,&lt;br /&gt;        EnrollmentNumber = "BE20111234"&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    Student davidBaker = new Student() {&lt;br /&gt;        FirstName = "David",&lt;br /&gt;        LastName = "Baker",&lt;br /&gt;        Course = mastersBusiness,&lt;br /&gt;        Address = string.Empty,&lt;br /&gt;        EnrollmentNumber = "MB20111234"&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    Institute rafaelInstitute = new Institute() {&lt;br /&gt;        Name = "St. Rafael Institute for Higher Studies",&lt;br /&gt;        Address = "123, Orleans Dr., Santa Clara, CA 94902",&lt;br /&gt;        Rating = 3&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    rafaelInstitute.Students.Add(steveRichards);&lt;br /&gt;    rafaelInstitute.Students.Add(davidBaker);&lt;br /&gt;&lt;br /&gt;    University testUniversity = new University() {&lt;br /&gt;        Name = "State University of California",&lt;br /&gt;        Address = "Palo Alto, CA, 92033",&lt;br /&gt;        Rating = 5&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    testUniversity.AffiliatedInstitutes.Add(rafaelInstitute);&lt;br /&gt; testUniversity.SaveToXML(@"F:\" + testUniversity.Name + ".xml");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When we are good so far, here is the XML you should already have written somewhere on your disk-&lt;br /&gt;&lt;br /&gt;&lt;pre class="xml" name="code"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;University xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;  &amp;lt;AffiliatedInstitutes&amp;gt;&lt;br /&gt;    &amp;lt;Institute&amp;gt;&lt;br /&gt;      &amp;lt;Students&amp;gt;&lt;br /&gt;        &amp;lt;Student&amp;gt;&lt;br /&gt;          &amp;lt;FirstName&amp;gt;Steve&amp;lt;/FirstName&amp;gt;&lt;br /&gt;          &amp;lt;LastName&amp;gt;Richards&amp;lt;/LastName&amp;gt;&lt;br /&gt;          &amp;lt;Address /&amp;gt;&lt;br /&gt;          &amp;lt;EnrollmentNumber&amp;gt;BE20111234&amp;lt;/EnrollmentNumber&amp;gt;&lt;br /&gt;          &amp;lt;Course&amp;gt;&lt;br /&gt;            &amp;lt;Name&amp;gt;Bachelor of Engineering&amp;lt;/Name&amp;gt;&lt;br /&gt;            &amp;lt;DurationInMonths&amp;gt;48&amp;lt;/DurationInMonths&amp;gt;&lt;br /&gt;            &amp;lt;CourseType&amp;gt;Graguate-Degree&amp;lt;/CourseType&amp;gt;&lt;br /&gt;          &amp;lt;/Course&amp;gt;&lt;br /&gt;        &amp;lt;/Student&amp;gt;&lt;br /&gt;        &amp;lt;Student&amp;gt;&lt;br /&gt;          &amp;lt;FirstName&amp;gt;David&amp;lt;/FirstName&amp;gt;&lt;br /&gt;          &amp;lt;LastName&amp;gt;Baker&amp;lt;/LastName&amp;gt;&lt;br /&gt;          &amp;lt;Address /&amp;gt;&lt;br /&gt;          &amp;lt;EnrollmentNumber&amp;gt;MB20111234&amp;lt;/EnrollmentNumber&amp;gt;&lt;br /&gt;          &amp;lt;Course&amp;gt;&lt;br /&gt;            &amp;lt;Name&amp;gt;Masters of Business Administration&amp;lt;/Name&amp;gt;&lt;br /&gt;            &amp;lt;DurationInMonths&amp;gt;24&amp;lt;/DurationInMonths&amp;gt;&lt;br /&gt;            &amp;lt;CourseType&amp;gt;PG-Degree&amp;lt;/CourseType&amp;gt;&lt;br /&gt;          &amp;lt;/Course&amp;gt;&lt;br /&gt;        &amp;lt;/Student&amp;gt;&lt;br /&gt;      &amp;lt;/Students&amp;gt;&lt;br /&gt;      &amp;lt;Name&amp;gt;St. Rafael Institute for Higher Studies&amp;lt;/Name&amp;gt;&lt;br /&gt;      &amp;lt;Address&amp;gt;123, Orleans Dr., Santa Clara, CA 94902&amp;lt;/Address&amp;gt;&lt;br /&gt;      &amp;lt;Rating&amp;gt;3&amp;lt;/Rating&amp;gt;&lt;br /&gt;    &amp;lt;/Institute&amp;gt;&lt;br /&gt;  &amp;lt;/AffiliatedInstitutes&amp;gt;&lt;br /&gt;  &amp;lt;Name&amp;gt;State University of California&amp;lt;/Name&amp;gt;&lt;br /&gt;  &amp;lt;Address&amp;gt;Palo Alto, CA, 92033&amp;lt;/Address&amp;gt;&lt;br /&gt;  &amp;lt;Rating&amp;gt;5&amp;lt;/Rating&amp;gt;&lt;br /&gt;&amp;lt;/University&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-7341927065546361382?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/7341927065546361382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2011/10/serializing-net-classes-into-xml.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7341927065546361382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7341927065546361382'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2011/10/serializing-net-classes-into-xml.html' title='Serializing .NET Classes into XML (C#)'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-2410777423927778318</id><published>2010-12-19T00:56:00.000+05:30</published><updated>2012-01-03T15:02:04.674+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Events and Delegates'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Delegates in C#</title><content type='html'>A &lt;b&gt;Delegate&lt;/b&gt; in C# is a method that points to another method with same signature. &lt;br /&gt;&lt;br /&gt;Think it as an expression which allows you to invoke any method whose signature matches to the signature of delegate itself.  &lt;br /&gt;&lt;br /&gt;In a real life programming example, suppose you have a button control and you have some code to be executed when this button is clicked. What if your Button control would have come with a specific method name, which only could be invoked when you click the button? &lt;br /&gt;You could not change the name of the method and it would get worse when you have more than one similar Button controls on the form each demanding an event handler method.&lt;br /&gt;&lt;br /&gt;The solution to this problem comes with delegates. You simply add a Click EventHandler to the button and assign a method which will be invoked when button is clicked. &lt;br /&gt;&lt;br /&gt;More or less, it looks like this: &lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;Button1.Click += new EventHandler(Button1_Click);&lt;br /&gt;&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;Click&lt;/i&gt; (in &lt;i&gt;Button1.Click&lt;/i&gt;) is a delegate (of type EventHandler) defined for Button control which can invoke a method with &lt;i&gt;void&lt;/i&gt; as return type and two arguments (&lt;i&gt;object &lt;/i&gt;and &lt;i&gt;EventArgs&lt;/i&gt;).&lt;br /&gt;&lt;br /&gt;It doesn't care about the name of the method until you pass it to the constructor of EventHandler (&lt;i&gt;new EventHandler(...)&lt;/i&gt;). &lt;br /&gt;&lt;br /&gt;It means that if it would have been any method with return type &lt;i&gt;void&lt;/i&gt; as return type and two arguments (&lt;i&gt;object &lt;/i&gt;and &lt;i&gt;EventArgs&lt;/i&gt;), you can invoke it on click event of Button control by delegating it to the Click Event of button.&lt;br /&gt;&lt;br /&gt;Button was an example from inbuilt control library. It is already implemented with a delegate of type EventHandler defined as:&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;public delegate void EventHandler(object sender, EventArgs e);&lt;br /&gt;&lt;/pre&gt;The Button class defines an event of this type EventHandler as: &lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;public event EventHandler Click;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, when you need to call a method on click of this Button, you &lt;a href="http://msdn.microsoft.com/en-us/library/system.multicastdelegate.aspx"&gt;multicast&lt;/a&gt; the Click Event to your method by using &lt;i&gt;+= new ...&lt;/i&gt; expression. It means that you can assign more than one methods (with same signature as that of delegate) in the invocation list of the delegate. All of these methods will be invoked when this event is called.&lt;br /&gt;&lt;br /&gt;So, delegates play an important role to allow the programmers to call any method (of delegate's signature) without knowing its name at design time.&lt;br /&gt;&lt;br /&gt;Delegates behave like classes and structs. By default, they have internal access when declared directly within a namespace, and private access when nested.&lt;br /&gt;&lt;br /&gt;There is a limited flexibility available in .NET with the signature of methods which are to be passed to delegates. In other words, methods don't need to match the delegate signature exactly. &lt;a href="http://msdn.microsoft.com/en-us/library/ms173174%28v=vs.80%29.aspx"&gt;MSDN&lt;/a&gt; describes more on this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-2410777423927778318?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/2410777423927778318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/12/delegates-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/2410777423927778318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/2410777423927778318'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/12/delegates-in-c.html' title='Delegates in C#'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-6989842918650797376</id><published>2010-10-19T23:32:00.000+05:30</published><updated>2012-01-03T14:59:15.443+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF WinForm Interoperability'/><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><title type='text'>Host WPF Controls in Windows Forms</title><content type='html'>To host a WPF control or WPF user control (&lt;span style="color: #6aa84f;"&gt;wpfControl&lt;/span&gt;&lt;b&gt; &lt;/b&gt;in this example) into Windows Form application, create an instance of &lt;span style="color: #38761d;"&gt;ElementHost &lt;/span&gt;Class and add your WPF control/user control as child to the instance of &lt;span style="color: #38761d;"&gt;ElementHost&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;using System.Windows.Forms.Integration; &lt;br /&gt;//Assembly:   WindowsFormsIntegration (in WindowsFormsIntegration.dll)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;ElementHost elementHost = new ElementHost();&lt;br /&gt;elementHost.Dock = DockStyle.None;&lt;br /&gt;elementHost.Child = wpfControl;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now, add the instance of &lt;span style="color: #6aa84f;"&gt;ElementHost &lt;/span&gt;to a container control in your windows form (for instance &lt;span style="color: #6aa84f;"&gt;containerPanel&lt;/span&gt;&lt;span style="color: #38761d;"&gt; &lt;/span&gt;here)&lt;br /&gt;&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;containerPanel.Controls.Add(elementHost);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-6989842918650797376?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/6989842918650797376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/10/host-wpf-controls-in-windows-forms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/6989842918650797376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/6989842918650797376'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/10/host-wpf-controls-in-windows-forms.html' title='Host WPF Controls in Windows Forms'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-3716995563112754315</id><published>2010-10-04T00:03:00.000+05:30</published><updated>2012-01-03T15:02:29.008+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><title type='text'>Online WPF Learning Material (Updated)</title><content type='html'>Save Google from doing it again. I've done it already. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/silverlight/mvvm-explained.aspx?artkw=wpf%20rich%20text%20box"&gt;MVVM in WPF &lt;/a&gt;&lt;br /&gt;An introduction to the Model-View-ViewModel (MVVM) pattern in WPF&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms752299.aspx"&gt;Walkthrough: Getting Started with WPF&lt;/a&gt;&lt;br /&gt;WPF's official education library from Microsoft.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://windowsclient.net/learn/videos_wpf.aspx"&gt;WindowsClient.NET&lt;/a&gt;&lt;br /&gt;An excellent list of video tutorials useful to beginners and proficient WPF programmers. My personal favorite in WPF video tutorials.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.wpftutorial.net/WPFIntroduction.html"&gt;WPFTutorials.NET&lt;/a&gt;&lt;br /&gt;Great collection of WPF tutorials including source code examples. Right place to start learning WPF from. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.dotnetfunda.com/articles/article882-wpf-tutorial--a-beginning--1-.aspx"&gt;WPF Tutorial&lt;/a&gt;&lt;br /&gt;Nice tutorials for beginners including WPF basics, Layout - Panels &amp;amp; Containers, Borders, TypeConverter &amp;amp; MarkupExtensions to XAML, Dependency Property System and Concept Binding.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://dotnetslackers.com/articles/silverlight/WPFTutorial.aspx"&gt;WPF Tutorial&lt;/a&gt; (dotnetslackers.com)&lt;br /&gt;Good resource to start for beginners providing &lt;span id="ctl00_ArticleInfo1_desc"&gt;general overview of the key concepts and innovations of WPF.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://wpfwonderland.wordpress.com/"&gt;&lt;span id="ctl00_ArticleInfo1_desc"&gt;WPF Wonderland&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span id="ctl00_ArticleInfo1_desc"&gt;Collection of adhoc task related articles about&amp;nbsp; WPF and Silverlight.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="ctl00_ArticleInfo1_desc"&gt;&lt;a href="http://joshsmithonwpf.wordpress.com/"&gt;Josh Smith's Blog&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;Expert articles on WPF and Silverlight.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://mydotnetexperiences.blogspot.com/2009/07/wpf-beginners-tutorial-part-1.html"&gt;WPF - Beginners tutorial&lt;/a&gt;&lt;br /&gt;One page tutorial on basics of WPF.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.aspfree.com/c/a/BrainDump/XAML-Basics/"&gt;XAML Basics&lt;/a&gt;&lt;br /&gt;Mutlipage introduction to XAML. Useful for WPF and Silverlight beginners.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/WPF/BeginWPF1.aspx"&gt;WPF: A Beginner's Guide&lt;/a&gt; (&lt;b&gt;CodeProject.com&lt;/b&gt;) &lt;br /&gt;Multipart WPF tutorial series. CodeProject articles rock!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/WPF/"&gt;Windows Presentation Foundation&lt;/a&gt; (&lt;b&gt;CodeProject.com&lt;/b&gt;)&lt;br /&gt;Huge and excellent collection of useful adhoc articles on WPF. Includes a number of sample applications.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;WPF Apps With The MVVM Design Pattern &lt;/a&gt;&lt;br /&gt;Official content on The Model-View-ViewModel Design Pattern for WPF from MS.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Many more to be explored and to be appended..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-3716995563112754315?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/3716995563112754315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/10/online-wpf-learning-material.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/3716995563112754315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/3716995563112754315'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/10/online-wpf-learning-material.html' title='Online WPF Learning Material (Updated)'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-889959217652873623</id><published>2010-05-08T11:59:00.001+05:30</published><updated>2012-01-03T13:33:20.455+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET 2.0'/><title type='text'>Reset values of all controls using ASP.NET 2.0 and JavaScript</title><content type='html'>&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt; line-height: 115%;"&gt;    A very common requirement that comes up when building a form with lot of fields    is resetting the controls back to their original state. In this article, we will    explore how to do this task using both ASP.NET and Javascript. I assume you know    how to build web pages in asp.net 2.0.&lt;/span&gt; &lt;b&gt;&lt;span style="font-family: 'Verdana','sans-serif';        font-size: 10pt; line-height: 115%;"&gt;&lt;u style="display: none;"&gt;Using ASP.NET&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br/&gt;&lt;b&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt; line-height: 115%;"&gt;    Step 1: &lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt;        line-height: 115%;"&gt;Drag and drop a few controls like textboxes, radio buttons,        checkboxes etc. on to the form&lt;/span&gt; &lt;b&gt;&lt;span style="font-family: 'Verdana','sans-serif';            font-size: 10pt; line-height: 115%;"&gt;&lt;br/&gt;Step 2:&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: 'Verdana','sans-serif';                font-size: 10pt; line-height: 115%;"&gt; Add a button to the form and rename its Text                property&amp;nbsp;as “Clear all controls using ASP.NET”. &amp;nbsp;Rename its id property                to be “btnClearASP”.&lt;/span&gt; &lt;b&gt;&lt;span style="font-family: 'Verdana','sans-serif';                    font-size: 10pt; line-height: 115%;"&gt;&lt;br/&gt;Step 3: &lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: 'Verdana','sans-serif';                        font-size: 10pt; line-height: 115%;"&gt;Double click the button. In its&amp;nbsp;click                        event,&amp;nbsp;call a method that will clear the content of the controls on a Page.&lt;/span&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt; line-height: 115%;"&gt;&lt;/span&gt;&lt;pre class="c-sharp" name="code"&gt;protected void btnClearASP_Click(object sender, EventArgs  e)&lt;br /&gt;    {&lt;br /&gt;        ResetFormControlValues(this);&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt; line-height: 115%;"&gt;    Write code for this method &lt;/span&gt;&lt;br /&gt;&lt;div style="margin: 0in 0in 10pt;"&gt;    &lt;span style="font-family: 'Verdana','sans-serif'; font-size: 10pt; line-height: 115%;"&gt;        C#&lt;/span&gt;&lt;/div&gt;&lt;pre class="c-sharp" name="code"&gt;private void ResetFormControlValues(Control parent)&lt;br /&gt;    {&lt;br /&gt;        foreach (Control c in parent.Controls)&lt;br /&gt;        {&lt;br /&gt;            if (c.Controls.Count &gt; 0)&lt;br /&gt;            {&lt;br /&gt;                ResetFormControlValues(c);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                switch(c.GetType().ToString())&lt;br /&gt;                {&lt;br /&gt;                    case "System.Web.UI.WebControls.TextBox":&lt;br /&gt;                        ((TextBox)c).Text = "";&lt;br /&gt;                        break;&lt;br /&gt;                    case "System.Web.UI.WebControls.CheckBox":&lt;br /&gt;                        ((CheckBox)c).Checked = false;&lt;br /&gt;                        break;&lt;br /&gt;                    case "System.Web.UI.WebControls.RadioButton":&lt;br /&gt;                        ((RadioButton)c).Checked = false;&lt;br /&gt;                        break;&lt;br /&gt;                 &lt;br /&gt;                }              &lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-889959217652873623?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/889959217652873623/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/05/reset-values-of-all-controls-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/889959217652873623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/889959217652873623'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/05/reset-values-of-all-controls-using.html' title='Reset values of all controls using ASP.NET 2.0 and JavaScript'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-2455093934989737192</id><published>2010-02-12T13:04:00.000+05:30</published><updated>2012-01-03T13:33:34.608+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='DotNetNuke'/><title type='text'>Developing a new module in DNN 5</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;1. Open the DNN website in VS 2008, right click the website node in solution explorer, add new item, select DotNetNuke module, name your DNN module, add.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://arpit.6te.net/dotnetways/create-new-module1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="249" src="http://arpit.6te.net/dotnetways/create-new-module1.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;2. Do a Project wide search &amp;amp; replace on YourCompany keyword. replace it with your comapny name of choice.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://arpit.6te.net/dotnetways/create-new-module2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://arpit.6te.net/dotnetways/create-new-module2.jpg" width="264" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;3. Go to App_code folder of DNN website and rename the 'ModuleName' folder by name of your module.&lt;br /&gt;&lt;br /&gt;4. Go to web.config, look for&amp;nbsp; &lt;codesubdirectories&gt; tag inside &lt;compilation&gt; and add a directory with name of your module (same as in step 3)&lt;/compilation&gt;&lt;/codesubdirectories&gt;&lt;br /&gt;&lt;br /&gt;5. Go to 'DesktopModules'&amp;gt; 'ModuleName' and rename it, same as in step no 3.&lt;br /&gt;&lt;br /&gt;6. Build your website to make sure that everything is OK.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;7. Open the DNN website in browser, login into the Host account.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_8W4aFuulEZs/S3UEGixsTvI/AAAAAAAACWU/rk0m3_MyGls/s1600-h/create-new-module3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_8W4aFuulEZs/S3UEGixsTvI/AAAAAAAACWU/rk0m3_MyGls/s320/create-new-module3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;7. Go to Host&amp;gt; Module Definitions&amp;gt; Create New Module&amp;gt; select Create Menu from: Menifest, select your modulename in 'Module Folder' dropdown, Create Module.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_8W4aFuulEZs/S3UEQBmMV8I/AAAAAAAACWc/MoidQJ48UoY/s1600-h/create-new-module4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_8W4aFuulEZs/S3UEQBmMV8I/AAAAAAAACWc/MoidQJ48UoY/s320/create-new-module4.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;8. Switch to VS2008, open '01.00.00.SqlDataProvider' file in DesktopModules&amp;gt; Your-Module-Name-Folder and copy the SQL.&lt;br /&gt;&lt;br /&gt;9. Go to website&amp;gt; Host&amp;gt; SQL&amp;gt; Paste the script copied in step 9 here, check the Run as Script checkbox, Execute. It should reply as "The Query completed successfully!".&lt;br /&gt;&lt;ol&gt;&lt;/ol&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_8W4aFuulEZs/S3UEZHsCV_I/AAAAAAAACWk/tP-uGAoPcyg/s1600-h/create-new-module5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_8W4aFuulEZs/S3UEZHsCV_I/AAAAAAAACWk/tP-uGAoPcyg/s320/create-new-module5.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&amp;nbsp;You are done with your new module.&lt;br /&gt;&lt;br /&gt;I will continue to blog about how to add features to your module.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-2455093934989737192?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/2455093934989737192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/02/developing-new-module-in-dnn-5.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/2455093934989737192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/2455093934989737192'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/02/developing-new-module-in-dnn-5.html' title='Developing a new module in DNN 5'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_8W4aFuulEZs/S3UEGixsTvI/AAAAAAAACWU/rk0m3_MyGls/s72-c/create-new-module3.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-8543376634680979559</id><published>2010-02-04T16:54:00.000+05:30</published><updated>2010-02-04T16:55:27.460+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='DotNetNuke'/><title type='text'>Adding a 3rd party module to DotNetNuke portal</title><content type='html'>And finally I succeeded to add a 3rd party module Smart-Thinker UserProfile and use it in my DNN portal!&lt;br /&gt;&lt;br /&gt;Here are the footprints:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; 1. Download the module extension from Smart-Thinker's portal. Its Free!!&lt;br /&gt;&amp;nbsp;&amp;nbsp; 2. Login into your portal using host account credentials.&lt;br /&gt;&amp;nbsp;&amp;nbsp; 3. Go to Host&amp;gt; Basic Features&amp;gt; Module Definitions&amp;gt; Install Module at the bottom of the page.&lt;br /&gt;&amp;nbsp;&amp;nbsp; 4. A new screen with title 'Install Extension' appears, browse the downloaded module extension and click next. After passing some confirmation screens, you should be able to install the module successfully.&lt;br /&gt;&amp;nbsp;&amp;nbsp; 5. Now when we have installed the module successfully, we are ready to consume it. Naviagate to a page of your choice in your DNN portal, on the top of the page, select Module: 'Smart-Thinker UserProfile Profile', Pane:Content pane, Title: 'Profile', Visibility: Same as page, Insert: Bottom and click 'Add Module to Page'.&lt;br /&gt;&amp;nbsp;&amp;nbsp; 6. Now on the same page, in the content page, a container with title 'Smart-Thinker UserProfile Profile' should appear.&lt;br /&gt;&amp;nbsp;&amp;nbsp; 7. You can customize it by clicking settings icon in the right bottom of this container.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-8543376634680979559?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/8543376634680979559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/02/adding-3rd-party-module-to-dotnetnuke.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/8543376634680979559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/8543376634680979559'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/02/adding-3rd-party-module-to-dotnetnuke.html' title='Adding a 3rd party module to DotNetNuke portal'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-7117307518733976024</id><published>2010-01-30T18:14:00.000+05:30</published><updated>2010-01-30T18:28:53.829+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='DotNetNuke'/><title type='text'>Day 1 with Dot Net Nuke</title><content type='html'>&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;Register to &lt;a href="http://www.dotnetnuke.com/"&gt;DotNetNuke&lt;/a&gt; and &lt;a href="http://dotnetnuke.codeplex.com/"&gt;download &lt;/a&gt;the latest version of DotNetNuke Community Edition.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;Extract it and configure it as a website in IIS. Let’s call it ‘DNN website’.&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;Open the DNN website in Visual Studio 2008.&lt;/li&gt;&lt;li&gt;On running it the installation page appears - http://localhost/dotnetnuke/Install/InstallWizard.aspx.&lt;/li&gt;&lt;li&gt;In select installation method, select typical, choose language English, click Next button.&lt;/li&gt;&lt;li&gt;On next page, test permissions of the application, when you pass the sufficient permission test, click next.&lt;/li&gt;&lt;li&gt;On next page you have to configure database connections. Configure your database here.&amp;nbsp; Click next.&amp;nbsp; It will complete the installation itself. On page 'Run Database Installation Scripts' in the textbox when you see 'Installation of Database Complete' click next. Also check-out the database you configured in previous page. You will see many tables and stored procedures created by DNN. Click next.&lt;/li&gt;&lt;li&gt;On the next page, 'Configure Host Account' create your SuperAdmin username and password. This username and password you will use to access your website's admin part. Click next.&lt;/li&gt;&lt;li&gt;Next page with title ‘Portal title’, provide host username/password and title to your portal. The host username/password will be used to access all the functionality of the portal. Submit the page and done! We have created our Dot Net Nuke portal.&lt;/li&gt;&amp;nbsp;&lt;/ol&gt;&lt;div style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;  Problem: #1&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; While accessing the DNN portal using IP or DNS (not localhost) it redirects to http://localhost/...&lt;br /&gt;&lt;br /&gt;Solution:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;Log in as host account.&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;Then go to the Admin &amp;gt; Site Settings page&lt;span style="font-size: small;"&gt;.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;Advanced Settings&amp;gt; Portal Aliases&amp;gt; add a new Http Alias "domain.com/…"&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-7117307518733976024?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/7117307518733976024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/day-1-with-dot-net-nuke.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7117307518733976024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7117307518733976024'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/day-1-with-dot-net-nuke.html' title='Day 1 with Dot Net Nuke'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-8069871884610710573</id><published>2010-01-27T12:37:00.000+05:30</published><updated>2012-01-03T13:33:53.865+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSMQ'/><title type='text'>Microsoft Message Queue MSMQ Part-I</title><content type='html'>&lt;b&gt;Microsoft Message Queue MSMQ&lt;/b&gt;&lt;br /&gt;In distributed applications sometimes two applications needs to communicate in an asynchronous manner that is one application shoots a message for another, another application which may not be available at the same time, but could get that message at a later time. This functionality can be achieved by storing the message sent by first application into a central database and then when later application becomes available to process this message, it could receive the message from the database. Let’s look a bit deeper. It is OK to use a central database when you need only two applications to communicate, but how if you have a thousand applications to send messages and only one application to process them?&lt;br /&gt;For example, you want to accept data from multiple users and you have to do some operations on that data, after that you require writing data to some files. Then in this situation you don’t need the data to be stored in database, you just want to do some operations on that data and copy that to some files. Microsoft Message Queue (MSMQ) fills this need by providing a central location or pool where you can place or remove data. An application can place data in the queue and continue with its business while another application grabs the data when it is ready.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What is Message Queuing?&lt;/b&gt;&lt;br /&gt;Message queuing is a communication tool that allows applications to reliably interconnect in a distributed environment where one of the applications may or may not be available at any given time. The queue acts as a holding container for messages as they are sent between applications. The applications send messages to and read messages from queues to communicate back and forth. An application writes a message to a queue, which will then be received and processed by another application at some point determined by the receiving application. This type of communication is designed for asynchronous use where the applications involved are not waiting for an immediate response from the other end. The key feature of message queues like MSMQ is the fact that it decouples sender and recipient applications so they do not need to run at the same time. This means that an application can place data in the queue and not deal with whether the item on the queue is delivered to the recipient.&lt;br /&gt;MSMQ is a part of the Windows Server operating system. Originally MSMQ came with a native, COM-based programming interface. But Microsoft has added a.NET wrapper on top of it which makes the development of MSMQ-based systems quite easier.  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_8W4aFuulEZs/S1_mBYblYBI/AAAAAAAACVw/gNAR9AWDspw/s1600-h/image11.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_8W4aFuulEZs/S1_mBYblYBI/AAAAAAAACVw/gNAR9AWDspw/s320/image11.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;When to Use Message Queue? &lt;/b&gt;&lt;br /&gt;a. Storing insignificant information in the message queue while your database server is busy with other real time processing. &lt;br /&gt;b. Process user input which is given by the user after getting supporting information from other source or applications that are not active or ready at this stage. &lt;br /&gt;c. Because of database server outage, you might require keeping user input in the message queue and processing it as and when the database comes online. &lt;br /&gt;d. Exchanging data with a mainframe system like SAP. Personally, the real time communication with SAP is often a problem. In such cases, the SAP system uses message queue for storing and forwarding information where real time communication is not possible at that time.&lt;br /&gt;So, in MSMQ there are two concepts – the Message and the Message-Queue&lt;br /&gt;• &lt;b&gt;Message&lt;/b&gt;: The actual message or data to be shared among applications.&lt;br /&gt;• &lt;b&gt;Message&lt;/b&gt;-&lt;b&gt;Queue&lt;/b&gt;: The MSMQ message queue that will receive/send messages.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Types of Message Queues&lt;/b&gt;&lt;br /&gt;• &lt;b&gt;Outgoing&lt;/b&gt;: Used to temporarily store messages before they are sent to its destination.&lt;br /&gt;• &lt;b&gt;Public&lt;/b&gt;: Published in the Active Directory. Applications on different servers throughout the network can find and use public queues via Active Directory.&lt;br /&gt;• &lt;b&gt;Private&lt;/b&gt;: These queues are local to a server and are not available to other machines (thus, these queues are not published in Active Directory).&lt;br /&gt;• &lt;b&gt;System&lt;/b&gt;: Contains journal messages (sent from the system), dead messages, and transactional dead-letter messages. Dead messages are undeliverable.&lt;br /&gt;&lt;br /&gt;continued..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-8069871884610710573?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/8069871884610710573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/microsoft-message-queue-msmq-part-i.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/8069871884610710573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/8069871884610710573'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/microsoft-message-queue-msmq-part-i.html' title='Microsoft Message Queue MSMQ Part-I'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_8W4aFuulEZs/S1_mBYblYBI/AAAAAAAACVw/gNAR9AWDspw/s72-c/image11.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-958165103525722776</id><published>2010-01-18T16:31:00.000+05:30</published><updated>2012-01-03T13:34:23.674+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Binary stream to Image'/><title type='text'>Saving image from binary stream</title><content type='html'>In a project I encountered a problem where I needed to capture binary stream of an image which was drawn on flash and was sent to an ASPX page to handle the stream, convert it into the same image that was drawn and save it to disk (on the server) or throw it out of the browser as a download.&lt;br /&gt;Google got exact place for me &lt;a href="http://stackoverflow.com/questions/1028039/what-is-the-net-c-equivilent-of-httprawpostdata"&gt;here&lt;/a&gt;, but the food was not yet ready to be fed. It is really annoying to see large number of GDI+ System.Drawing Exceptions. So, here is what I stopped at fighting the those exceptions-&lt;br /&gt;&lt;pre class="c-sharp" name="code"&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        //Get the stream&lt;br /&gt;        Stream input = (Stream)Request.InputStream;&lt;br /&gt;&lt;br /&gt;        Bitmap bmp = new Bitmap(input);&lt;br /&gt;&lt;br /&gt;        // Clear current content and set returned content type&lt;br /&gt;        Response.Clear();&lt;br /&gt;        Response.ContentType = "image/jpeg";&lt;br /&gt;        &lt;br /&gt;        // Save to the Response.OutputStream object&lt;br /&gt;        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);&lt;br /&gt;&lt;br /&gt;        bmp.Dispose();&lt;br /&gt;        Response.End();&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-958165103525722776?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/958165103525722776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/saving-image-from-binary-stream.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/958165103525722776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/958165103525722776'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/saving-image-from-binary-stream.html' title='Saving image from binary stream'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-7901905014497011205</id><published>2010-01-18T16:16:00.000+05:30</published><updated>2012-01-03T13:34:45.935+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET 2.0'/><title type='text'>Displaying Warning Messages in ASP.NET page- II</title><content type='html'>Displaying Web Warning Messages: Technique 2&lt;br /&gt;There are times when you want to draw attention to an important message, without being overly loud. Sometimes, all you want to say is... "Thank you! Your information has been stored" or "Finished: all your outstanding reviews have been completed."&lt;br /&gt;In these situations, a message box is a little overkill. Slightly more placid is the technique of displaying a whole Web page with just your core message at its center. I also prefer to add automatic redirects on such pages, so that after a few seconds, the user gets taken back to the previous page, or through to the next.&lt;br /&gt;There are two ways to achieve this goal. First, create a separate page in your application that accepts a message in its query string, and then send your user across to that page.&lt;br /&gt;Alternatively, you can do it wholly in code—which is just what we're doing here. I've created a small method holding a core HTML Web page, which you could perhaps load from a file. Inside that page, we have numerous variables (such as a message description) that get replaced by the method. Then, we push the modified HTML down the wire as a response to our client.&lt;br /&gt;The HTML also contains a HTTP Refresh command, which by default takes the user back to the previous page. So, in brief: When you call the function, it displays a message for a number of seconds, and then returns to the issuing page.&lt;br /&gt;Here's the function you'll need:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;public void DisplayMessage(string MsgTitle, string MsgDetails, string PageTitle, int DelayInSeconds)&lt;br /&gt;    {&lt;br /&gt;      PageTitle = &amp;quot;Attention!&amp;quot;;&lt;br /&gt;      DelayInSeconds = 2;&lt;br /&gt;      string strResponse = &amp;quot;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;%page-title%&amp;lt;/title&amp;gt;&amp;lt;META HTTP-EQUIV=&amp;#39;Refresh&amp;#39; &amp;quot;  &lt;br /&gt;        &amp;quot;CONTENT=&amp;#39;%delay%; url=javascript:history.back();&amp;#39;&amp;gt;&amp;quot;  &lt;br /&gt;        &amp;quot;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;div align=&amp;#39;center&amp;#39;&amp;gt;&amp;lt;center&amp;gt;&amp;quot;  &lt;br /&gt;        &amp;quot;&amp;lt;table border=&amp;#39;0&amp;#39;cellpadding=&amp;#39;0&amp;#39; cellspacing=&amp;#39;0&amp;#39; width=&amp;#39;100%&amp;#39; height=&amp;#39;100%&amp;#39;&amp;gt;&amp;lt;tr&amp;gt; &amp;quot;  &lt;br /&gt;        &amp;quot;&amp;lt;td width=&amp;#39;100%&amp;#39;&amp;gt; &amp;lt;p align=&amp;#39;center&amp;#39;&amp;gt;&amp;lt;b&amp;gt; &amp;lt;font face=&amp;#39;Arial&amp;#39; size=&amp;#39;6&amp;#39;&amp;gt;%message-title%&amp;quot;  &lt;br /&gt;        &amp;quot;&amp;lt;/font&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;p align=&amp;#39;center&amp;#39;&amp;gt;&amp;lt;font face=&amp;#39;Arial&amp;#39; size=&amp;#39;3&amp;#39;&amp;gt;&amp;lt;b&amp;gt;%message-details%&amp;lt;/b&amp;gt;&amp;quot;  &lt;br /&gt;        &amp;quot;&amp;lt;/font&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;;&lt;br /&gt;&lt;br /&gt;      strResponse = strResponse.Replace(&amp;quot;%page-title%&amp;quot;, PageTitle);&lt;br /&gt;      strResponse = strResponse.Replace(&amp;quot;%message-title%&amp;quot;, MsgTitle);&lt;br /&gt;      strResponse = strResponse.Replace(&amp;quot;%message-details%&amp;quot;, MsgDetails);&lt;br /&gt;strResponse = strResponse.Replace(&amp;quot;%delay%&amp;quot;,   DelayInSeconds.ToString);&lt;br /&gt;&lt;br /&gt;      Response.Clear();&lt;br /&gt;      Response.Write(strResponse);&lt;br /&gt;      Response.End();&lt;br /&gt;    }&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;DisplayMessage(&amp;quot;Thanks&amp;quot;, &amp;quot;You are being redirected now&amp;quot;, &lt;br /&gt;&amp;quot;Thanks!!!&amp;quot;, 3);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-7901905014497011205?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/7901905014497011205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/displaying-warning-messages-in-aspnet_18.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7901905014497011205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/7901905014497011205'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/displaying-warning-messages-in-aspnet_18.html' title='Displaying Warning Messages in ASP.NET page- II'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1361326064122483419.post-4288611438438707305</id><published>2010-01-18T16:12:00.000+05:30</published><updated>2012-01-03T13:35:07.024+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET 2.0'/><title type='text'>Displaying Warning Messages in ASP.NET pages- I</title><content type='html'>Thought of a situation when you need to call javascript alert from your server side code that might include some server side decision logic to handle the alert. Most of us know a straight way- "Page.ClientScript.RegisterStartupScript" method to accomplish this. Althoght accidentally, I came to know another approach to do the same without - &amp;nbsp; "Page.ClientScript.RegisterStartupScript".&lt;br /&gt;&lt;br /&gt;Switch to the HTML view of your Web form and add the following immediately after the close of the &amp;lt;body&amp;gt; tag:&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; &amp;gt;&lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;lt;asp:Literal id=&amp;quot;ltlAlert&amp;quot; runat=&amp;quot;server&amp;quot; EnableViewState=&amp;quot;False&amp;quot;&amp;gt;    &amp;lt;/asp:Literal&amp;gt;&lt;br /&gt; &amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;Switch back to Design view and save your Web form. This has set up your Literal server control manually—due to the surrounding &amp;lt;script&amp;gt; tags; we couldn't do this using the designer&lt;br /&gt;Add the following code snippet behind your Web form. This takes a string and incorporates it into a JavaScript 'alert' command, which is then placed on the Web page as pure HTML:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;private void Say(string Message)&lt;br /&gt;    {&lt;br /&gt;        // Format string properly &lt;br /&gt;        Message = Message.Replace("'", "\\'");&lt;br /&gt;        Message = Message.Replace(Convert.ToChar(10).ToString(), "\\n");&lt;br /&gt;        Message = Message.Replace(Convert.ToChar(13).ToString(), "");&lt;br /&gt;        // Display as JavaScript alert &lt;br /&gt;        ltlAlert.Text = "alert('" + Message + "')";&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;Whenever you want to display an in-your-face message, simply call this Say function in your code—as the following snippet demonstrates:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        Say("this is error msg\n next line");&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;Thats it!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1361326064122483419-4288611438438707305?l=www.arpitkhandelwal.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.arpitkhandelwal.com/feeds/4288611438438707305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/displaying-warning-messages-in-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/4288611438438707305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1361326064122483419/posts/default/4288611438438707305'/><link rel='alternate' type='text/html' href='http://www.arpitkhandelwal.com/2010/01/displaying-warning-messages-in-aspnet.html' title='Displaying Warning Messages in ASP.NET pages- I'/><author><name>Arpit Khandelwal</name><uri>http://www.blogger.com/profile/05954405367025998346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
