tag:blogger.com,1999:blog-77127316444052349242024-03-13T13:12:45.889+11:00C# Free Training CoursesMy journal of c# development experiences including Asp.net, windows and distributed applicationsEmad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-7712731644405234924.post-46124616883711361892011-09-04T13:31:00.003+10:002011-09-04T14:06:19.195+10:00Dance with LINQFor the first time I saw LINQ syntax I told to myself what the...
<br />How in the world I can understand and write LINQ syntax easily. What is LINQ in first place? Is there any value for me to learn this. Guess what I started to think in ways to use it. Then I found it very handy.
<br />In next posts I will try to teach you LINQ how to use it and how to understand exactly what are you doing and what LINQ can offer you.
<br />Let's start with what is LINQ. after all if you want to start dancing with it you need to know your partner otherwise your dance will not be that much sexy! eventhough you are a good dancer.
<br />
<br />LINQ is microsoft solution to query different sources like objects, XML, Dataset, SQL and entities easily with less code. However it is not just to query data. You can use LINQ to iterate items and even change thier types and use it to sort and etc.
<br />
<br />at this stage please do not worry about the code in future posts I will talk about C# 3.0 futures so you will understand exactly how LINQ works. in the following example a list of string numbers are changing to int and also they are get sorted. I am sure you see what a nice functionality it it.
<br />
<br />string[] mynums = {"34","020","3","16"};
<br />int[] nums = mynums.Select(s=> Int32.Parse(s)).OrderBy(s=>s).ToArray();
<br />foreach (int n in nums)
<br />Console.WriteLine(n);
<br />
<br />In next couple of posts I will talk about C# enhancements for LINQ so when we start LINQ then you have a better idea what is going on.
<br />
<br />Hopefully you liked the first dance class with LINQ.
<br />
<br />Please keep me updated.
<br />Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-26742051008594432632009-02-20T11:37:00.003+11:002009-02-20T11:44:44.794+11:00WCF Contracts<div align="justify">A contract is at name implies is a standard way of describing what a service can do. Meanwhile, it is platform independent. In WCF we have 4 types of contract:<br />· <strong>Service Contract</strong>: It defines what a client can do with the service.<br />· <strong>Data Contract</strong>: It defines which data types can be transferred in the service. ( by default you can pass basic types like int, string however for custom types like a custom class you need to define the class as a Data Contract to be able to pass object of that class in the service)<br />· <strong>Fault Contract</strong>: It defines what are the errors raised by service.<br />· <strong>Message Contract</strong>: It is an extra functionality allows you to send message in a customized way (It means that you need to send a message in a specific way because let’s say there is an existing system that just understands messages in a specific way. As a user of WCF you should not usually use this as you do not need it except you are working with very specific system that needs specific messaging system)<br /><br /><strong>Service Contract:</strong><br />To allow a WCF Client to understand what they can do with the service you need to use Service Contract which is an attribute you need to add to the class. Also for each method that you wish WCF client to access you need add OperationContract attribute take a look at this sample<br /><br />[ServiceContract]<br />Class MyService<br />{<br /> [OperationContract]<br /> public string MyOperation()<br /> {<br />return “hello World”;<br /> }<br />}<br /><br />As you see in above example we have ServiceContract for the class and we have OperationContract for the methods. Some Points:<br />· You can apply ServiceContract to a class or interface<br />· You have to apply OperatoinContract for methods otherwise it will not be accessible to clients<br />· You can only apply OperationContract to methods<br />· It is highly recommended first you better create an interface and apply the servicecontract then create a class that implements the interface (the reason will be discussed further)<br />· Methods accessibility is not important to WCF (public, private or internal) since they are CLR concepts not WCF<br />· Always the default constructor will be called (avoid parameterized constructors)<br />· You can define a Namespace for the ServiceContract (and it is suggested to do so) to avoid collision<br />Please see the same sample by using interface and namespace<br />[ServiceContract(Namespace=”mycompany.com”)]<br />interface IMyService<br />{<br /> [OperationContract]<br /> string MyOperation();<br />}<br />Class MyService:IMyService<br />{<br /> public string MyOperation()<br /> {<br />return “hello World”;<br /> }<br />}<br /><br /> </div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com2tag:blogger.com,1999:blog-7712731644405234924.post-18827738191912188692009-02-13T15:33:00.002+11:002009-02-13T15:46:19.865+11:00WCF Fundamentals<div align="justify">To work with WCF you need to understand these elements in WCF:<br />1-Addresses<br />2-Contracts<br />3-Bindings<br />4-Hostings<br />5-Endpoints<br />6-Metada exchanges<br />7- Client side Programming<br /><br /><strong><em>Addresses:<br /></em></strong>In WCF every service is associated with a unique address. Each address has two specifications. First it has the location of the service and second it has transport protocol. The location has the name of machine, a communication port and an optional specific path called URI. (URI is a unique string). WCF supports these protocols:<br />· HTTP : we use Http<br />· TCP : we use net.tcp<br />· Peer Network : we use net.p2p<br />· IPC: we use net.pipe<br />· MSMQ: we use net.msmq</div><div align="justify"><br />So the address has this format:<br /><strong>[transport protocol]:// [machine name][:optional port number]/[optional URI]</strong></div><div align="justify"><strong></strong></div><div align="justify">example: Http://myserver:4040/myservice</div><div align="justify"><br />You use each protocol based on requirement latter on when we talk about binding you will see that there are different bindings and for each binding you need to use one of the protocol then you have different kind of serialization & Interoperable functionality. </div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com1tag:blogger.com,1999:blog-7712731644405234924.post-28453769065419764212009-02-13T14:48:00.003+11:002009-02-13T14:53:08.273+11:00WCF & Service Oriented Architecture<div align="justify">Windows Communication Foundation (WCF) is a new technology in .Net 3.0/3.5 helps you to implement Service Oriented Architecture. This new technology not only allows you to work with previous services implemented by .Net Remoting or XML Web Services, but also has extensive functionality like instance management, asynchronous call, transaction management, disconnected queued calls, and security which can be applied through simple configuration. </div><p align="justify"><br />If you are going to write a service it is better use this technology as it gives lots of flexibility. For those of you who may not work with other technologies like Remoting, COM+ or XML Web Services and may not have experience with Service Oriented Architecture I should say Service Oriented Architecture tries to provide the functionality through services which are components hosted probably in another box. Applications can use these services.<br /><br />So if you have a code that you think different applications in internet / intranet may use it.You better provide that code as a service then your code centralized in one place while you can use extensive functionality through WCF.<br /><br />Please read my other posts for WCF comming soon. </p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-48428560772668559092009-02-13T08:57:00.002+11:002009-02-13T09:52:03.477+11:00Steps to learn SharePoint<div align="justify">SharePoint is a massive product. It is so huge which makes it difficult to know all parts of it. Having said that you need to know the product and be a good user of the product itself then you can try a path to make yourself professional in this product. I believe there are two types of professionalism in SharePoint. The first one is Administration and Configuration of SharePoint. The second one is Development and Customization of SharePoint. These are steps to be a professional programmer in SharePoint:</div><div align="justify"><br />1- Know the product and the functionality of it and the purpose<br />2- Be a good user of it (know how to use SharePoint)<br />3- Know how to install a SharePoint Server<br />4- Be able to understand differences between MOSS and WSS<br />5- Know how to use Out of the box features<br />6- Match the features to your company or a company<br />7- Understand different types of sites in SharePoint<br />8- Understand the connection of SharePoint and Office box<br />9- Be professional on creating Simple InfoPath forms<br />10- Configure a server farm<br />11- Create and manage content<br />12- Create a workflow<br />13- Manage enterprise search and indexing<br />14- Do Backup and recovery<br />15- Create a BDC<br />16- Develop a security topology<br />17- Configure other server platform to work with SharePoint<br />18- Know how to migrate from 2003 to 2007<br />19- Build collaboration and publish portals<br />20- Customize and brand your site with MasterPage, PageLayout, CSS, Themes and navigation<br />21- Customize and Create Workflow<br />22- How to deploy a workflow across servers<br />23- How to Use Form servers<br />24- How to use Excel Services<br />25- How to create Solution Package<br />26- How to use VS to Create Solutions<br /><br />I am sure there are so many items that I missed and I need your help to add more if you think I missed something just send a post and I will add it to the list.</div><div align="justify"><br />Anyway it is a long way to know SharePoint. At the first step my suggestion is that you can see 32 movies from Microsoft site to help you understand very basic functionalities of SharePoint.Just remember these movies are not covering all the functionalities but just part of them. </div><div align="justify"><br />This is the site you can see these movies: <a href="http://office.microsoft.com/en-us/sharepointserver/CH102066971033.aspx?stt=1">http://office.microsoft.com/en-us/sharepointserver/CH102066971033.aspx?stt=1</a></div><div align="justify"><br />This is the list of movies to help you to get an understanding of basic features.<br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102047921033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102047921033.aspx">Demo: Configure a SharePoint Server 2007 site to receive e-mail </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102050471033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102050471033.aspx">Demo: Deploy an administrator-approved form template </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500971033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500971033.aspx">Demo: Simplify collaboration with a SharePoint team site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501001033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501001033.aspx">Demo: Streamline business processes with forms and workflows </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102638391033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102638391033.aspx">Watch this: Create a presentation from slides in a slide library </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102659671033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102659671033.aspx">Watch this: Create and manage a SharePoint calendar </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102916051033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102916051033.aspx">Watch this: Find your way around a SharePoint team site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494741033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494741033.aspx">Watch this: Customize a site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494751033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494751033.aspx">Watch this: Automate business process with workflows </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103507051033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103507051033.aspx">Watch This: Tour of My Site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102753931033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102753931033.aspx">Watch this: Use Word 2007 to post to a SharePoint blog </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102769611033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102769611033.aspx">Watch this: Create a recurring meeting with a Meeting Workspace in a SharePoint calendar and then connect it to Outlook 2007 </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102741221033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102741221033.aspx">Watch this: Different ways to check documents in and out of a SharePoint site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102661781033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102661781033.aspx">Watch this: Make it easier to find information with views </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102515111033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102515111033.aspx">Demo: The new SharePoint Server 2007 Fluent interface </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102515411033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102515411033.aspx">Demo: Prepare to back up files on Office SharePoint Server </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501011033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501011033.aspx">Demo: Connect people to information with portals </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500981033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500981033.aspx">Demo: Enterprise Content Management with SharePoint Server 2007 </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500991033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102500991033.aspx">Demo: Search for information on a SharePoint site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102549161033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102549161033.aspx">Demo: Add KPIs to your SharePoint site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102689741033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102689741033.aspx">Demo: Back Up Office SharePoint 2007 </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102817151033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102817151033.aspx">Watch this: Using SharePoint to manage your classroom </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102549171033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102549171033.aspx">Demo: Display KPIs in a dashboard </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102662391033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102662391033.aspx">Watch this: Give a user access to a SharePoint site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494731033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494731033.aspx">Watch this: Work with documents offline in Outlook </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102693421033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102693421033.aspx">Watch this: Find just the data you need by using Filter Web Parts in a dashboard </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102817071033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102817071033.aspx">Watch this: Use a Document Workspace to collaborate on a document from a SharePoint library </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102078901033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102078901033.aspx">Demo: Enable Excel Services and data connections for a SharePoint team site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501021033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102501021033.aspx">Demo: Make better business decisions with reports and dashboards </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494761033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA103494761033.aspx">Watch this: Manage access to documents on My Site </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102506161033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102506161033.aspx">Watch this: Use an approval workflow in SharePoint Server 2007 </a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102742741033.aspx"></a><br /><a href="http://office.microsoft.com/en-us/sharepointserver/HA102742741033.aspx">Watch this: Create and publish Web pages on a publishing site </a><br /> </div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-73293988548438108912009-02-10T08:54:00.001+11:002009-02-10T08:55:48.334+11:00Preparing a SharePoint Server<div align="justify">To start SharePoint what you need is an environment that is properly setup. You need so many softwares in that machine. It is almost impossible for most of us having a Server 2003 at our PCs. since most of our computers are Notebook. You need a Server 2oo3 to install SharePoint. The best way to solve the issue is that you can install Virtual PC. This Software allows you to install different OS on your computer. What you need is at least 40GB hard and 1GB of RAM then I believe you can have rather well enough machines to install SharePoint. The first step is installing Virtual PC. It is free software and you can download from this link: </div><a href="http://microsoft-virtual-pc.en.softonic.com/">http://microsoft-virtual-pc.en.softonic.com/</a><br /><div align="justify"><br />Then you need to install Windows 2003 in Virtual Machine.Then all you need is following this link and follow 20 Steps to install SharePoint in a virtual PC:</div><br /><a href="http://www.sharepointblogs.com/mykiep/archive/2007/04/26/step-by-step-guide-for-installing-moss-2007-on-a-vpc.aspx">http://www.sharepointblogs.com/mykiep/archive/2007/04/26/step-by-step-guide-for-installing-moss-2007-on-a-vpc.aspx</a><br /><br />Then be ready to learn about SharePoint, InfoPath and Workflow.Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com1tag:blogger.com,1999:blog-7712731644405234924.post-47556569927514518812008-07-28T00:54:00.002+10:002008-07-28T01:09:14.593+10:00Command Pattern<p class="mobile-photo"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-xnAVX_mzEDGEFlYaoQpIrXmYqrouFDRD_aZT36BLgGqlwm2Tshj5nwvHW4mezfmYFkKbFeAMLaAJLt9r8Xf_FWipZyRJXGFuAC6ocFZyvQedkC75rVE1cZEHmGFLWltoLppw3BpZsCo/s1600-h/command-706001.gif"></a></p><div class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="center"><span lang="EN-AU"><span style="font-family:Calibri;"><a href="http://www.csharpcourses.com-a.googlepages.com/CommandPatternSample.rar">Please download the source code</a></span></span></div><p class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="center"><span lang="EN-AU"><span style="font-family:Calibri;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-xnAVX_mzEDGEFlYaoQpIrXmYqrouFDRD_aZT36BLgGqlwm2Tshj5nwvHW4mezfmYFkKbFeAMLaAJLt9r8Xf_FWipZyRJXGFuAC6ocFZyvQedkC75rVE1cZEHmGFLWltoLppw3BpZsCo/s1600-h/command-706001.gif"><img id="BLOGGER_PHOTO_ID_5227707524026686658" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-xnAVX_mzEDGEFlYaoQpIrXmYqrouFDRD_aZT36BLgGqlwm2Tshj5nwvHW4mezfmYFkKbFeAMLaAJLt9r8Xf_FWipZyRJXGFuAC6ocFZyvQedkC75rVE1cZEHmGFLWltoLppw3BpZsCo/s320/command-706001.gif" border="0" /></a></p><div class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br />This pattern is a behavioural pattern. Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.<br />If you look at the Class diagram you see that client set the receiver for ConcreteCommand. Invoker has a list of commands and translates which command should be executed based on condition. (Do not worry about the class diagram we get back to that in a sample). There are different variation for this pattern for example sometimes there are no receiver.<br />The Command Pattern encapsulates a single function free of any variables. "It elevates the role of a function to the level of a class" Robert C Martin. </div><div class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br /><strong>When to use this pattern?</strong><br />When you need to change a method to a class then you can have a group of function in shape of unique class. You can use this pattern to create Undo and Redo functions. You can use this pattern to decouple two behaviours that are highly coupled like validating and doing behaviour. You can use this pattern to route requests, execute actions or forward actions in a uniform way.<br />In this post I am going to give you a sample of this pattern in real world also in next post I will show you an example of Undo, Redo using Command Pattern.</div><div class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br /><strong>A real world Sample<br /></strong>I was assigned a task to implement a part of application. In that application users after selecting product and filling different information at final step had to select the payment method which was Credit Card and Ezi pay. The issue was that this application had many users so this part had to be implemented highly scalable and maintainable. I decided to use Command so users request from UI was changed to objects of requests. Because I was dealing with objects I could use message queuing also I could move this part to another server that do this so in that server the invoker did not have any idea about what sort of request are coming. A command was loaded and the execute method was called. I simplified the code and put it in one application to show you how amazing this pattern is. I made the UI very simple (just providing account number) however in real world it is more complex and each of these payments has its own attributes. Also you can check how many commands are in the queue. You can click on submit multiple times then by checking command numbers you see that there are some command in the queue that should be run. I used a queue list however in real world there are better way to implement. Let’s check the code:</div><div class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br /><strong>UICode:</strong></span></span></div><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';color:blue;" >protected</span><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" > <span style="color:blue;">void</span> butSubmitEzipay_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">EziPayCommand</span> cmd = <span style="color:blue;">new</span> <span style="color:#2b91af;">EziPayCommand</span>(txtAccountNum.Text);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Invoker</span>.Instance.AddCommand(cmd);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> butSubmitCredit_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">CreditCardCommand</span> cmd = <span style="color:blue;">new</span> <span style="color:#2b91af;">CreditCardCommand</span>(txtCreditCardNum.Text);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Invoker</span>.Instance.AddCommand(cmd);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> butCheck_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>lblComandCount.Text = <span style="color:#2b91af;">Invoker</span>.Instance.GetNumberofCommandRunning().ToString();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span><span lang="EN-AU" style="font-family:'Arial','sans-serif';"></span></p></td></tr></tbody></table><span lang="EN-AU" style="LINE-HEIGHT: 115%;font-family:'Arial','sans-serif';" ><p class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br />As you see for each submit button I am adding the correct command into Invoker object (a singleton object. Just in my case I decide to use Invoker as singleton the pattern do not suggest this however here I needed just one object to control all the request for command by adding commands in a queue and running them one by one) </p><p class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br /><strong>Invoker Class:</strong></span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Invoker</span></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:#2b91af;">Invoker</span> m_Instance;</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">bool</span> InProgress=<span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:#2b91af;">Invoker</span> Instance</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">get</span> </span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (m_Instance == <span style="color:blue;">null</span>)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>m_Instance = <span style="color:blue;">new</span> <span style="color:#2b91af;">Invoker</span>();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:#2b91af;">Invoker</span>.m_Instance; </span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Queue</span><<span style="color:#2b91af;">ICommand</span>> commandList = <span style="color:blue;">new</span> <span style="color:#2b91af;">Queue</span><<span style="color:#2b91af;">ICommand</span>>();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">void</span> AddCommand(<span style="color:#2b91af;">ICommand</span> cmd)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">lock</span> (<span style="color:blue;">this</span>)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>commandList.Enqueue(cmd);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>CheckForExecution();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:green;">//for testing</span></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">int</span> GetNumberofCommandRunning()</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> commandList.Count;</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">void</span> CheckForExecution()</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (!InProgress && commandList.Count > 0)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">ThreadStart</span> ts = <span style="color:blue;">new</span> <span style="color:#2b91af;">ThreadStart</span>(ExecuteCommand);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Thread</span> t = <span style="color:blue;">new</span> <span style="color:#2b91af;">Thread</span>(ts);</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>t.Start();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">void</span> ExecuteCommand()</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>InProgress = <span style="color:blue;">true</span>;</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">while</span> (commandList.Count > 0)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">lock</span> (<span style="color:blue;">this</span>)</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">ICommand</span> cmd = commandList.Dequeue();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>cmd.Execute();</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>InProgress = <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"><span style="mso-ansi-language: EN-US; mso-no-proof: yesfont-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span><span lang="EN-AU" style="font-family:'Arial','sans-serif';"></span></p></td></tr></tbody></table><span lang="EN-AU" style="LINE-HEIGHT: 115%;font-family:'Arial','sans-serif';" ><p class="MsoNormal" style="MARGIN: 0in 0in 10pt" align="justify"><br />As you see I used singleton pattern here to have just one Invoker object controlling all the command execution. Invoker puts all the requests in a queue and run them one by one. When a command is added to the queue we check wether execution has been started if it is not started by creating new thread we start the process in a separate thread. In the execution process, a command is loaded and it will be run. As you see In Invoker we do not care about type of Command and Invoker itself has no idea which type of command it is running. </span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com3tag:blogger.com,1999:blog-7712731644405234924.post-28315085828632934132008-07-20T21:44:00.002+10:002008-07-20T21:46:33.032+10:00Design Patterns<p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">A Design pattern is a general reusable solution to a commonly occurring problem in software design. Each pattern has an intention that try to solve a common problem. You need to know the intention of each pattern also the problem they solve then if you come up with that issue you need to apply that pattern to solve the problem. I have seen so many programmers have no idea about design pattern if you are part of those people I should say you are not classified as senior programmer. I believe a senior programmer need to know these patterns. I could find a big gap in terms of design patterns knowledge between Java programmers and C# programmers. Java programmers know design patterns very well however; C# programmers hardly know them and use them. I had a lot of co-workers writing horrible codes just because they do not know how to solve a common problem. I wish I had a chance to convince them apart from technologies like <a href="http://asp.net/">ASP.NET</a>, WCF, WF, and etc you need much more deep understanding about coding and design patterns otherwise you may know amazing technology but you do not have enough capacity to use them correctly!</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">This is why I decided to start writing about design patterns and give you some idea about them and also share my experiences over some of these patterns.</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">I hope you can find this useful. Please follow my post about design patterns and help me to correct myself also share your experiences with me.</span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com1tag:blogger.com,1999:blog-7712731644405234924.post-19331327091345021802008-07-20T10:29:00.005+10:002008-07-20T10:57:17.263+10:00A sample of Multi Thread programming in Asp.net<p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="center"><span style="font-family:Calibri;font-size:100%;"><a href="http://www.csharpcourses.com-a.googlepages.com/MultiThreadApp.zip">Download The Source Code</a></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="center"><span style="font-family:Calibri;"><a href="#" onclick= "window.open('http://www.csharpcourses.com-a.googlepages.com/MultiThreadSample.html')">Please See the clip</a></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Understanding the issue</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">I was assigned to implement a part of web application that was responsible for calling a java based application.<span style="mso-spacerun: yes"> </span>There were some concerns about this part of application as follows:</span></p><p class="MsoListParagraphCxSpFirst" dir="ltr" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1" align="justify"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">1.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">The java based application was supposed to create a file that I had to process that file and show to user</span></p><p class="MsoListParagraphCxSpMiddle" dir="ltr" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1" align="justify"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">2.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">A user could run the process from a page but after running he was not able to run it again (since the process took 3 min)</span></p><p class="MsoListParagraphCxSpMiddle" dir="ltr" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1" align="justify"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">3.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">When application was running no one else could run application but they were supposed to see that application was run by someone else.</span></p><p class="MsoListParagraphCxSpMiddle" dir="ltr" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1" align="justify"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">4.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Page should be updated every 10 seconds to check whether the process is finished or not</span></p><p class="MsoListParagraphCxSpLast" dir="ltr" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1" align="justify"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">5.</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">When process is finished a file was generated I saved the file output in a temporary table (for simplicity I will save this data in a static variable)</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">To simulate this let's say we have an application called ExternalApp (a console application) to create a file but creating that file may take 3 min.</span></p><div dir="ltr"><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:10;" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span><span style="font-size:100%;"><span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (args.Length == 1)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>System.Threading.<span style="color:#2b91af;">Thread</span>.Sleep(180000);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">StreamWriter</span> w = <span style="color:blue;">new</span> <span style="color:#2b91af;">StreamWriter</span>(args[0],<span style="color:blue;">false</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">for</span>(<span style="color:blue;">int</span> i=0;i<10;i++)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>w.WriteLine(<span style="color:#a31515;">" A Sample Data :"</span>+ i);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>w.Close();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p></td></tr></tbody></table></div><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">Now we should create a web application to call this application by using Multi thread programming.</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">First I create a library to run the external application in a separate method. We need to check whether the process of running is finished or not. I created two classes one was Director another one was Builder. </span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">Take a look at Director Class:</span></p><div dir="ltr"><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >public</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">class</span> <span style="color:#2b91af;">Director</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Builder</span> builder;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> userName;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:#2b91af;">List</span><<span style="color:blue;">string</span>> Result = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span><<span style="color:blue;">string</span>>();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:#2b91af;">AlgorithemStatus</span> Constract(<span style="color:#2b91af;">Builder</span> builder,<span style="color:blue;">string</span> user)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">this</span>.userName = user;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (<span style="color:#2b91af;">HttpContext</span>.Current.Application[<span style="color:#a31515;">"athread"</span>] == <span style="color:blue;">null</span>)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">this</span>.builder = builder;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">ThreadStart</span> ts = <span style="color:blue;">new</span> <span style="color:#2b91af;">ThreadStart</span>(RunThread);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Thread</span> t = <span style="color:blue;">new</span> <span style="color:#2b91af;">Thread</span>(ts);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>t.Start();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">HttpContext</span>.Current.Application[<span style="color:#a31515;">"athread"</span>] = t;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:#2b91af;">AlgorithemStatus</span>.AlgorithemRunSuccessful;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">else</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:#2b91af;">AlgorithemStatus</span>.AlgorithemWasRunning;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">bool</span> IsAlgorithemRunning</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">get</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (<span style="color:#2b91af;">HttpContext</span>.Current.Application[<span style="color:#a31515;">"athread"</span>] == <span style="color:blue;">null</span>)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">else</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Thread</span> t = <span style="color:#2b91af;">HttpContext</span>.Current.Application[<span style="color:#a31515;">"athread"</span>] <span style="color:blue;">as</span> <span style="color:#2b91af;">Thread</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (!t.IsAlive)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">HttpContext</span>.Current.Application.Remove(<span style="color:#a31515;">"athread"</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">else</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">void</span> RunThread()</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">try</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>builder.PrepareHistoryFolder(userName);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>builder.RunExternalAll();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>Result = builder.LoadResult();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>System.IO.<span style="color:#2b91af;">StreamWriter</span> w = <span style="color:blue;">new</span> System.IO.<span style="color:#2b91af;">StreamWriter</span>(System.Configuration.<span style="color:#2b91af;">ConfigurationManager</span>.AppSettings[<span style="color:#a31515;">"HistoryPath"</span>] + <span style="color:#a31515;">"\\err.log"</span>, <span style="color:blue;">true</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>w.WriteLine(<span style="color:#a31515;">"Date Time : "</span> + <span style="color:#2b91af;">DateTime</span>.Now);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>w.WriteLine(ex.ToString());</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>w.Close();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p></td></tr></tbody></table></div><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">In This class construct create a new thread and run RunThread method in it. IsAlgorithemRunning Property Check whether the running process has been started. Finally RunThread method calls different method in builder class and retrieve the result.</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">Check the Builder Class:</span></p><div dir="ltr"><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >using</span><span style="mso-no-proof: yes;font-family:'Courier New';" > System;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >using</span><span style="mso-no-proof: yes;font-family:'Courier New';" > System.Collections.Generic;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >using</span><span style="mso-no-proof: yes;font-family:'Courier New';" > System.Text;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >using</span><span style="mso-no-proof: yes;font-family:'Courier New';" > System.IO;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >namespace</span><span style="mso-no-proof: yes;font-family:'Courier New';" > AlgorithemManagment</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Builder</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">string</span> pathResultExteranlApp;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">string</span> pathExternalApp;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:#2b91af;">StreamWriter</span> statswriter;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">internal</span> <span style="color:blue;">void</span> PrepareHistoryFolder(<span style="color:blue;">string</span> userName)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:green;">//Check for History folder first</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> path = System.Configuration.<span style="color:#2b91af;">ConfigurationManager</span>.AppSettings[<span style="color:#a31515;">"HistoryPath"</span>];</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (!<span style="color:#2b91af;">Directory</span>.Exists(path))</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Directory</span>.CreateDirectory(path);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> foldername = <span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"{0:d4}_{1:d2}_{2:d2}_{3:d2}_{4:d2}_{5:d2}"</span>, <span style="color:#2b91af;">DateTime</span>.Now.Year, <span style="color:#2b91af;">DateTime</span>.Now.Month, <span style="color:#2b91af;">DateTime</span>.Now.Day, <span style="color:#2b91af;">DateTime</span>.Now.Hour, <span style="color:#2b91af;">DateTime</span>.Now.Minute, <span style="color:#2b91af;">DateTime</span>.Now.Second);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> HistoryPaht = path + <span style="color:#a31515;">"\\"</span> + foldername;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">Directory</span>.CreateDirectory(HistoryPaht);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>pathResultExteranlApp = HistoryPaht + <span style="color:#a31515;">"\\Result.CSV"</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>pathExternalApp = System.Configuration.<span style="color:#2b91af;">ConfigurationManager</span>.AppSettings[<span style="color:#a31515;">"ExteranlAppPath"</span>]; </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> pathstats = HistoryPaht + <span style="color:#a31515;">"\\stats.log"</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>statswriter = <span style="color:blue;">new</span> <span style="color:#2b91af;">StreamWriter</span>(pathstats, <span style="color:blue;">true</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>statswriter.WriteLine(<span style="color:#a31515;">"User who runned the Algorithem:<span style="mso-spacerun: yes"> </span>"</span> + userName);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>statswriter.WriteLine(<span style="color:#a31515;">"Starting DateTime:<span style="mso-spacerun: yes"> </span>"</span> + <span style="color:#2b91af;">DateTime</span>.Now.ToString());</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">internal</span> <span style="color:blue;">void</span> RunExternalAll()</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>System.Diagnostics.<span style="color:#2b91af;">Process</span> prc = <span style="color:blue;">new</span> System.Diagnostics.<span style="color:#2b91af;">Process</span>();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>prc.StartInfo.FileName = pathExternalApp;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>prc.StartInfo.Arguments = pathResultExteranlApp;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (prc.Start())</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>statswriter.WriteLine(<span style="color:#a31515;">"Allocatoin application has just started at "</span> + <span style="color:#2b91af;">DateTime</span>.Now.ToString());</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>prc.WaitForExit();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">internal</span> <span style="color:#2b91af;">List</span><<span style="color:blue;">string</span>> LoadResult()</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">List</span><<span style="color:blue;">string</span>> strs = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span><<span style="color:blue;">string</span>>();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">StreamReader</span> r = <span style="color:#2b91af;">File</span>.OpenText(pathResultExteranlApp);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> data = r.ReadLine();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">while</span> (data != <span style="color:blue;">null</span>)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>strs.Add(data);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>data = r.ReadLine();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>statswriter.WriteLine(<span style="color:#a31515;">"Temptable was filled successfully DateTime:"</span> + <span style="color:#2b91af;">DateTime</span>.Now.ToString());</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>statswriter.Close();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> strs;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" >}</span></p></td></tr></tbody></table></div><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">PrepareHistoryFolder creates a history folder to log and also save the result. RunExternalApp runs the External application and wait until it result is generated. LoadResult read the file generated by external app and process it.</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">Check the Page code:</span></p><div dir="ltr"><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >protected</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">void</span> Page_Load(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (<span style="color:#2b91af;">Director</span>.IsAlgorithemRunning)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>PrepareDisableMode();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">else</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>PrepareEnableMode();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">void</span> PrepareEnableMode()</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>ButtonRunAlgorithm.Enabled = <span style="color:blue;">true</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>imgwait.Visible = <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>DataListResult.Visible = <span style="color:blue;">true</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (<span style="color:#2b91af;">Director</span>.Result.Count > 0)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>DataListResult.DataSource = <span style="color:#2b91af;">Director</span>.Result;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>DataListResult.DataBind();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">private</span> <span style="color:blue;">void</span> PrepareDisableMode()</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span>ButtonRunAlgorithm.Enabled = <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>imgwait.Visible = <span style="color:blue;">true</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>ClientScript.RegisterStartupScript(<span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>), <span style="color:#a31515;">"mykey"</span>, <span style="color:#a31515;">"<script>RefreshPageinSecond();</script>"</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>DataListResult.Visible = <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> ButtonRunAlgorithm_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>PrepareDisableMode();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>AlgorithemManagment.<span style="color:#2b91af;">Director</span> d = <span style="color:blue;">new</span> AlgorithemManagment.<span style="color:#2b91af;">Director</span>();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>AlgorithemManagment.<span style="color:#2b91af;">Builder</span> b = <span style="color:blue;">new</span> AlgorithemManagment.<span style="color:#2b91af;">Builder</span>();</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>d.Constract(b,<span style="color:#a31515;">"The User Name"</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span>}</span></p></td></tr></tbody></table></div><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"></span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">When page is load if algorithm is running we are disabling the button and showing an image indicating we are middle of the process. If algorithm is not running we enable the button and also show the result. When button is clicked we disable button and show the image and also run the algorithm.</span></p><p class="MsoNormal" dir="ltr" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">Please see the clip to understand the code better.<br /></span><span style="font-family:Calibri;">Please download the source code and also go to web.config file and update the </span><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';font-size:10;color:blue;" ><span style="font-size:100%;">ExteranlAppPath</span> </span><span style="font-family:Calibri;">which is the address of ExternalApp exe file and update the </span><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';font-size:10;color:blue;" ><span style="font-size:100%;">HistoryPath </span></span><span style="font-family:Calibri;font-size:100%;">which is the address of history folder to log information.</span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-76084821829662047602008-07-03T08:00:00.002+10:002008-07-03T08:04:01.024+10:00Multi Thread Programming in .NET<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">What is multi thread programming?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Multi thread programming allows you to do two or more tasks at the same time. As a windows user you have experienced doing two or more tasks together for example while you are listening to music you are using word at the same time you may printing a picture as well. It means that your computer has the ability of doing some tasks simultaneously. Multi thread programming gives you a chance to do this with different parts of the code.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;"><span style="mso-spacerun: yes"> </span>What is process?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Process is a space assigned by CPU allows the code to be run in that space.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">What is Thread?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Each process has at least one Thread which is a reference for CPU to run next line in that process</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">A better definition for Multi threads programming:</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Create different thread in current process to run two different parts of the code simultaneously.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;"><span style="mso-spacerun: yes"> </span>Why do we need Multi thread programming?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Each process has at least one thread that run the code called main thread. Sometimes we cannot hang main thread because it is reflecting the hang issue to user. Let me give you an example. Let's say we have a windows application and in part of our code we need to run an external application which may take 1 minute to run. But we cannot spend 1 minute to run this application because the main thread is responsible to render user interface as well so we may create a new thread to do this task for us and leave the main thread to take care of user interface. You see sometimes without multi thread programming our code is not efficient. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">How multi thread programming works in .net?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Thanks to .net framework where you can find so many ways to implement multi thread programming. Even you can find this awesome technology in <a href="http://ado.net/">ado.net</a> and UI and... I am going to start from very basic one which is the simple Thread class. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">First rule in multi thread programming is that you can run part of your code in another thread as long as your code is defined in a method. It means that if you need to run part of your code in new thread you need to define that code in a method. So a new thread can be run over a method. In .Net there are two classes that help you to do this first is Thread class and second ThreadStart delegate. By ThreadStart you define the address of the method you need to run in a new Thread. By Thread class you start the Thread. Take a look at this code:</span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:#2b91af;" >ThreadStart</span><span style="mso-no-proof: yes;font-family:'Courier New';" > ts = <span style="color:blue;">new</span> <span style="color:#2b91af;">ThreadStart</span>(myfunction);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:#2b91af;" >Thread</span><span style="mso-no-proof: yes;font-family:'Courier New';" > t = <span style="color:blue;">new</span> <span style="color:#2b91af;">Thread</span>(ts);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >t.Start();</span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><br /><span style="font-family:Calibri;font-size:100%;">In above code first myfunction address is assigned to ts delegate then a new object of Thread is created and in constructor the ts is passed to thread object so when Start is called it will start the new thread for ts which is actually myfunction.</span></p><p align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-bidi-: minor-bidifont-family:'Times New Roman';font-size:85%;" >I was always asked by students where do we use this how we can use this in a web based application it may not be useful for a web based application. But the reality is that you can use this even in a web based application in next post I show you how! I was assigned a small project that I had to use multi thread programming </span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com3tag:blogger.com,1999:blog-7712731644405234924.post-17356957467732084422008-06-19T13:18:00.003+10:002008-06-19T13:26:20.991+10:00Passing viewstates of a page to another page<p class="mobile-photo" align="center"><span style="font-family:Calibri;font-size:100%;"><a href="http://www.csharpcourses.com-a.googlepages.com/postbackurlsample.zip">Download the source code</a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Sometimes we need to pass information of one page to the next page to do this there are different approaches one of them is that you can pass just a querystring then lookup data in your data source. However sometimes there are no data sources so you need to have all states of one page in another page. So you may use Session object to pass this information. However, this may not be the best way because you are using Session object which is shared between different pages for a user. There is another way which is PostBackUrl.(In next posts I will compare State Management in <a href="http://asp.net/">asp.net</a>) </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">How to pass viewstate by PostBackURL</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">After Visualstudio 2005 all our buttons has a nice properties called PostBackUrl which can be assigned to a page then state of this page (the page that has button with PostBackUrl) will be passed to Next page.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Take a look at this:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKOQOf3_9Rk7e3AJDI5MQYXNSCWkKE-6BgCMHvimgVhDx1lElk0uHjD2j-bWZu0WJsLvSp1nCI4a5iavanDEEWVAKzjRITZXeJBENA07CMPHtzUoo2flPCdMEOzRiQoXAkTx9Dbo_cFPA/s1600-h/Snap2-789667.jpg"><img id="BLOGGER_PHOTO_ID_5213426679871540274" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKOQOf3_9Rk7e3AJDI5MQYXNSCWkKE-6BgCMHvimgVhDx1lElk0uHjD2j-bWZu0WJsLvSp1nCI4a5iavanDEEWVAKzjRITZXeJBENA07CMPHtzUoo2flPCdMEOzRiQoXAkTx9Dbo_cFPA/s320/Snap2-789667.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl6xLpAmBFnU75cnWNPV7vOyh_iSSvmBWtegCxPZTNJubGgfuCswtEznN_6ehcmo8DgL7yo97LH2nsLpPaW0EKczp7AT4on7iSt7vCdLkskzr2NESkWS0KDSxCCP85NG0hGeN5sW-3XWY/s1600-h/Snap1-789292.jpg"><img id="BLOGGER_PHOTO_ID_5213426678505394130" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl6xLpAmBFnU75cnWNPV7vOyh_iSSvmBWtegCxPZTNJubGgfuCswtEznN_6ehcmo8DgL7yo97LH2nsLpPaW0EKczp7AT4on7iSt7vCdLkskzr2NESkWS0KDSxCCP85NG0hGeN5sW-3XWY/s320/Snap1-789292.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">In this example we have a textbox and a dropdownlist and we need to see state of these two controls in next page. Also we have a button that its PostBackUrl is set to a page. When user click on this button the state is passed to next page to access these states you need to use PreviousPage object. Remember if someone tries to access this page by giving this page address into browser or user is redirected from other redirection method Then PreviousPage object is null. So to be in safe side always check this object. Take a look to this code:</span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >if</span><span style="mso-no-proof: yes;font-family:'Courier New';" > (PreviousPage != <span style="color:blue;">null</span>)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">DropDownList</span> lst = PreviousPage.FindControl(<span style="color:#a31515;">"DropDownList1"</span>) <span style="color:blue;">as</span> <span style="color:#2b91af;">DropDownList</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (lst != <span style="color:blue;">null</span>)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>LabelDropdown.Text = lst.Text;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:#2b91af;">TextBox</span> txt = PreviousPage.FindControl(<span style="color:#a31515;">"TextBox1"</span>) <span style="color:blue;">as</span> <span style="color:#2b91af;">TextBox</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">if</span> (txt != <span style="color:blue;">null</span>)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>LabelTextbox.Text = txt.Text;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">As you see in the code we are checking PreviousPage object so we are sure that previous page state is passed to this page it means that redirection method was PostBackUrl.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Also we have another method to make controls type safe which is defining PreviousPageType Directive (in html code) but the issue with this approach is that you can define one page as your previous page. Also if user access to this page with any other of redirection method then an error will be generated. So I highly recommend you use the previous approach and never user PreviousPageType directive.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Let's see the steps:</span></p><p class="MsoListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">1-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Define a page with a button which its PostBackUrl is filled with a page ( we call it target page)</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">2-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">In Target page Use PreviousPage.FindControl to access controls in previous page.</span></p><p class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">3-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Always check PreviousPage object to be sure it is not null</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: center" align="center"><span style="font-family:Calibri;font-size:100%;"><a href="http://www.csharpcourses.com-a.googlepages.com/postbackurlsample.zip">Download the source code</a></span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com6tag:blogger.com,1999:blog-7712731644405234924.post-40148567669145276202008-06-18T08:54:00.003+10:002008-06-18T09:03:02.911+10:00Control structures in C#<p class="mobile-photo"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">These structures are as follows:</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >if</span><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;"> (expression) </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:teal;" >statement1...[n]</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >elseif</span><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;"> (expression)</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:teal;" >statement1...[n]</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">} </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:blue;" >else</span><span lang="EN-US" style="mso-bidi-language: FA"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:teal;" >statement1...[n]</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;">}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Please pay attention to logical operators && and while using then as a expression in <i>if structure </i>because as we explain earlier they won't check the second operand if the first one fulfill the condition.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >while</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (expression)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:teal;" >statement1...[n]</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:85%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >do</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:teal;" >statement1...[n]</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >} <span style="color:blue;">while</span> (expression);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">In comparison between <i>while</i> and <i>do while</i> , do while will execute the statement at least once.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >To explain <i>for stucture</i> we can express an example to clarify it.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >for</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (int i = 1; i < 10;i++ )</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine(i);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Another control structure is <i>for each. </i>But before we go through it, we should know what arrays are. That's because <i>for each</i> is used only with a of collection entities, collection of data types.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Times New Roman;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >Structure of <i>foreach</i> is as bellow.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >foreach</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (<span style="color:blue;">collectionDataType </span>varName <span style="color:blue;">in</span> collectionName)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;">{<span style="mso-spacerun: yes"> </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >statement1…[n];</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">It means that each item in collection will be assigned to varName then the code in the block will be run for varName.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Array</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Arrays are of those kinds of variables that are placed in heap memory.(go to first lesson, memory management)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Array is a collection of specific data type. Let's have an example to understand both <i>for each</i> control structure and <i>arrays</i>.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >[] nums = <span style="color:blue;">new</span> <span style="color:blue;">int</span> [3];</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >nums[0] = 10;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >nums[1] = 15;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >nums[2] = 20;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > sum = 0;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >foreach</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (<span style="color:blue;">int</span> n <span style="color:blue;">in</span> nums )</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;">{<span style="mso-spacerun: yes"> </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >sum = sum + n ;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine(<span style="color:maroon;">"The summary is :{0}"</span> ,sum);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Courier New;font-size:85%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><span lang="EN-US">In above code each item in nums is assigned to n and then the code in the block will be run for each item.</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:10;" ></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Break<span style="mso-spacerun: yes"> </span>and Continue</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">It's time now to talk about <i>break</i> and <i>continue. </i>Remember that, these two statements are using in loop structures. Like for, while, do while and …. Let's see the usage of them in an example.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">If you run the following code snippet you will see that when i =5 the code will stop. It means although i is less that 100 but the rest of code won't execute.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >for</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (<span style="color:blue;">int</span> i = 1; i < 100; i++)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >if</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (i%5 == 0)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine(<span style="color:maroon;">"Hope!"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >break</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > ;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine(i);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">The result will be as follow</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="center"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqhHHGpybSyKZR87OGZPBsjI0hwCBciwCmuWEpcGmjTlI6bQUPvzZLx-T-XiVhymgLw41HlwK5grhuwAGGtLpI2ERu1EXNA9swBKcxtA34kExvdDy10Op_Xtbl2wZTO-dCFWeLIwvctFE/s1600-h/Snap3-761093.jpg"><img id="BLOGGER_PHOTO_ID_5212987612125108658" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqhHHGpybSyKZR87OGZPBsjI0hwCBciwCmuWEpcGmjTlI6bQUPvzZLx-T-XiVhymgLw41HlwK5grhuwAGGtLpI2ERu1EXNA9swBKcxtA34kExvdDy10Op_Xtbl2wZTO-dCFWeLIwvctFE/s320/Snap3-761093.jpg" border="0" /></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Figure 4</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">But if you change the code like this:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >for</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (<span style="color:blue;">int</span> i = 1; i < 100; i++)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >if</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (i%5 == 0)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 72pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.Write Line(<span style="color:maroon;">"Hope!"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >continue</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > ;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine(i);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Courier New;font-size:85%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Instead of each number that is dividable to 5 the word "Hope" will be printed. The result of running the above code snippet is shown in figure 5</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="center"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjvX7dpx0oZAQ-bT0sVQvVwHmwTtXfZlRi_5epPiVWPgbAHSsFLYa6s60Bi8UQBlUqr8gLMM-KdmbIcrcmI8LTpld9Id2Dqxvi34K4T3spPv8L0yPKqg-QrnLx5DMiO6vsG7S-wtAoPGQ/s1600-h/Snap4-761942.jpg"><img id="BLOGGER_PHOTO_ID_5212987614466822402" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjvX7dpx0oZAQ-bT0sVQvVwHmwTtXfZlRi_5epPiVWPgbAHSsFLYa6s60Bi8UQBlUqr8gLMM-KdmbIcrcmI8LTpld9Id2Dqxvi34K4T3spPv8L0yPKqg-QrnLx5DMiO6vsG7S-wtAoPGQ/s320/Snap4-761942.jpg" border="0" /></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Figure 5</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Note: You are not allowed to change the value of the counter in the <i>foreach</i> control structure. This is a read only value. It means you can not change the value of i in the code above.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">GoTo:</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">Probably no other construct in programming history is as maligned as the <i>goto</i> statement. The problem with using <i>goto</i> is use of it in inappropriate places.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">The structure of <i>goto </i>is </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Times New Roman;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >goto</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > <i>lableName</i>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><i><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >lableName</span></i><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;"><span style="font-size:85%;"><span style="mso-tab-count: 1"></span>Statement1…[n];</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">It is hardly recommended to use goto because it reduces the performance of the application, except in some cases that it will increase the performance. Using goto in nested loops that <i>break </i>can't help you will be very handy.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Switch case</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Another control structure is <i>switch </i>with the following structure<i></i></span></span></span></p><pre><span style="font-size:85%;"> </span><span lang="EN-US" style="font-size:100%;">switch (<span class="variable">expression</span>)</span></pre><pre><span lang="EN-US">{ </span></pre><pre><span lang="EN-US"> case <span class="variable">constant-expression</span>:</span></pre><pre><span lang="EN-US"> <span class="variable">statement</span></span></pre><pre><span lang="EN-US"> <span class="variable">jump-statement</span></span></pre><pre><span lang="EN-US"> case <span class="variable">constant-expressionN</span>:</span></pre><pre><span lang="EN-US"> <span class="variable">statementN</span></span></pre><pre><span lang="EN-US"> [default]</span></pre><pre><span lang="EN-US">}</span></pre><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US"><span style="font-family:Times New Roman;">In this structure as you can see if you write even one <span class="variable">statement you should have a jump-statement that can be <i>break </i>or <i>got </i>otherwise you as a programmer will face an compile time error indicating that you lost a jump-statement. Don't forget to define <i>break</i> in default case. Let's explain the structure in a sample code.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span class="variable"><span lang="EN-US"><span style="font-family:Times New Roman;"></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine (<span style="color:maroon;">"Enter 10,20 or 30"</span>); </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > a =<span style="mso-spacerun: yes"> </span><span style="color:teal;">Convert</span>.ToInt32 ( <span style="color:teal;">Console</span>.ReadLine());</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >switch</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (a)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >case</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > 10:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">case</span> 20:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"></span><span style="color:teal;">Console</span>.WriteLine(<span style="color:maroon;">"I have more than {0} books"</span>, a);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">break</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">case</span> 30:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"></span><span style="color:teal;">Console</span>.WriteLine(<span style="color:maroon;">"I have {0} books"</span>, a);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">break</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;">In this case you won't get a compiler error because of not having <i>break </i>in the first <i>case </i>statement. The reason is you don't write any code for that specific case statement. This means compiler will execute codes till it arrives to a <i>break</i> or <i>goto</i>. If a user enters 10 as the value or 20 he will receive similar out puts.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;">But what if you want the compiler execute first and second statements that are in case 10 and 20 if user_entered_value is 10 and execute statement in second case if user_entered_value is 20. You simply can modify the code as bellow using goto.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:teal;" >Console</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" >.WriteLine (<span style="color:maroon;">"Enter 10,20 or 30"</span>); </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > a =<span style="mso-spacerun: yes"> </span><span style="color:teal;">Convert</span>.ToInt32 ( <span style="color:teal;">Console</span>.ReadLine());</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >switch</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > (a)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >case</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > 10:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-tab-count: 1;font-size:85%;" ></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">case</span> 20:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"></span><span style="color:teal;">Console</span>.WriteLine(<span style="color:maroon;">"I have more than {0} books"</span>, a);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">break</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">case</span> 30:</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="mso-tab-count: 1"></span><span style="color:teal;">Console</span>.WriteLine(<span style="color:maroon;">"I have {0} books"</span>, a);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">break</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-tab-count: 1;font-size:85%;" ></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Courier New;font-size:85%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; tab-stops: 54.75pt"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-size:100%;"><span style="font-family:Times New Roman;">please pay attention to the out put with different entered_values.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; tab-stops: 54.75pt"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; tab-stops: 54.75pt" align="center"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:10;" ><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUP2rGE1_GxKVzhC6fkNLidfxhD5Aw-z6EsnNzU6vFxsW8n8rMukq1c5OJhWTq43cY1KMZj9v3avug96wDjKbEcOxY40k81OEgeayPOdYBHCAXbzia7zpfOzMnanNcwGFK9hInAQu5TZY/s1600-h/Snap5-762997.jpg"><img id="BLOGGER_PHOTO_ID_5212987622668915250" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUP2rGE1_GxKVzhC6fkNLidfxhD5Aw-z6EsnNzU6vFxsW8n8rMukq1c5OJhWTq43cY1KMZj9v3avug96wDjKbEcOxY40k81OEgeayPOdYBHCAXbzia7zpfOzMnanNcwGFK9hInAQu5TZY/s320/Snap5-762997.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span class="variable"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span class="variable"><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Figure 6- User entered 10</span></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span class="variable"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span class="variable"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span class="variable"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcidZP5I6kgfBUvhgfqkAlxF5q71bcNbC-3IctGB5wilIedSQHOuiP_fiWCxDdg1CHea3EaqrMKYqnVvSiCoZfQlD7UQNTVOi4BNlcZ1xDH6nYxvGspHodaXCe3FhcVKPyBtdTGAKh934/s1600-h/Snap6-763750.jpg"><img id="BLOGGER_PHOTO_ID_5212987622262727778" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcidZP5I6kgfBUvhgfqkAlxF5q71bcNbC-3IctGB5wilIedSQHOuiP_fiWCxDdg1CHea3EaqrMKYqnVvSiCoZfQlD7UQNTVOi4BNlcZ1xDH6nYxvGspHodaXCe3FhcVKPyBtdTGAKh934/s320/Snap6-763750.jpg" border="0" /></a></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span class="variable"><span lang="EN-US"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Figure 6- User entered 20</span></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">"Thanks To Azadeh for writing this post"</span></span></span></b></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-16701278866277216592008-06-17T08:32:00.002+10:002008-06-17T08:38:37.470+10:00Access master page members from a page<p class="mobile-photo" align="center"><span style="font-family:Calibri;font-size:100%;"><a href="http://www.csharpcourses.com-a.googlepages.com/MasterPageAccessSample.zip">download the source code</a></span></p><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Sometimes we need define a property or a method in a masterpage and we need access to that property or method in pages that are using that masterpage. To do this we have two choices. </span></div><p class="MsoListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">1-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Using FindControl <span style="font-size:85%;">(</span></span><span style="font-size:85%;"><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';color:blue;" >this</span><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';" >.Master.FindControl(<span style="color:#a31515;">"usercontrolid"</span>))</span></span></p><p class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">2-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-size:100%;"><span style="font-family:Calibri;"><span style="mso-spacerun: yes"> </span>Using </span></span><span style="font-size:85%;"><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';color:blue;" >this</span><span style="LINE-HEIGHT: 115%; mso-no-proof: yesfont-family:'Courier New';" >.Master.YourProperty</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">The first one is not type safe so you could misspelled a property name then you will get null so this approach is error porn. Furthermore, the control should be cast to a valid control. Also you cannot access property by this approach but you can access to controls in masterpage. However, it does not need any other effort.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">The second one is type safe, access to masterpage properties is possible and there is no need for casting. However, it needs that the control be defined at least internal and you need define the master type in your page. Then compiler can detect that master page property and it allows you to access to those property through intelisence.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Let's see an example: we have a Label and image in our masterpage and we have some methods in our master page. We need to call these methods from page that is using these masterpage. Also we have a property in master page that we need to have access in our page. Take a look at this:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">This is the master page html code:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; tab-stops: 22.2pt"><span style="mso-tab-count: 1"><span style="font-family:Calibri;font-size:100%;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijfR8kCLybmTSPIKNKugnrkcwtld6HUzEmfd6cwYr5GpHJULLcY2gs-F3sUwbX-jsJbGI8vXdf5hRxlO12n3iZCsBg8uI6aFk6w4VGRDsv_9TMQy2eP-x239krbXR5hfFOmTi_Ex2OgrY/s1600-h/Snap1-724204.jpg"><img id="BLOGGER_PHOTO_ID_5212610785798240866" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijfR8kCLybmTSPIKNKugnrkcwtld6HUzEmfd6cwYr5GpHJULLcY2gs-F3sUwbX-jsJbGI8vXdf5hRxlO12n3iZCsBg8uI6aFk6w4VGRDsv_9TMQy2eP-x239krbXR5hfFOmTi_Ex2OgrY/s320/Snap1-724204.jpg" border="0" /></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">This master page properties and methods</span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >public</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:#2b91af;">Label</span> TitleLable</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">get</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">return</span> LabelTitle;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> ShowImage()</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>Image1.Visible = <span style="color:blue;">true</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> HideImage()</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>Image1.Visible = <span style="color:blue;">false</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Then we create a page that is using this masterpage. And this is the html code:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;"><span style="font-family:Calibri;"><b style="mso-bidi-font-weight: normal">Important:</b> in this code we defined a mastertype directive to notify compiler that we are using these masterpages then if you compile and try to access masterpage methods and properties you can see them.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-spacerun: yes"><span style="font-family:Calibri;font-size:100%;"> </span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA3_czaYlH3KEuUIH_Uk-jfFXG7BBR0syDjMM3PAE5xM4_X9xKeFDd1qAX2ApJgNU-ClHc37RMRixnS2xizHu_yWeaJ2ozXFx4uINDWgjqt5DSTkNIyXqwDUMZaQp2-tfU9KujylawgDY/s1600-h/Snap2-725237.jpg"><img id="BLOGGER_PHOTO_ID_5212610796292079282" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA3_czaYlH3KEuUIH_Uk-jfFXG7BBR0syDjMM3PAE5xM4_X9xKeFDd1qAX2ApJgNU-ClHc37RMRixnS2xizHu_yWeaJ2ozXFx4uINDWgjqt5DSTkNIyXqwDUMZaQp2-tfU9KujylawgDY/s320/Snap2-725237.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;"><span style="font-family:Calibri;"><span style="mso-spacerun: yes"> </span>Take a look to the code behind of the page. As you see we implemented both way. I highly recommend the second way. Remember the first way does not force you to define mastertype in the page. While, second way need the mastertype directive in html code of the page:</span></span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >protected</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">void</span> ButtonChangeTitle_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//first way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//Label lbl = Master.FindControl("LabelTitle") as Label;</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//lbl.Text = "New Title is Assigned";</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:green;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//second way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>Master.TitleLable.Text = <span style="color:#a31515;">"New Title is Assigned"</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> ButtonHideImage_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//first way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//Image img = Master.FindControl("Image1") as Image;</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//img.Visible = false;</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:green;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//second way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>Master.HideImage();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">protected</span> <span style="color:blue;">void</span> ButtonShowImage_Click(<span style="color:blue;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//first way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//Image img = Master.FindControl("Image1") as Image;</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//img.Visible = true;</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;color:green;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:green;">//second way</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>Master.ShowImage();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">As I said before I highly recommend the second way. Let's review the steps:</span></p><p class="MsoListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo2"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">1-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Create a master page</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo2"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">2-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Define some public properties and methods in masterpage</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo2"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">3-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Create a page using the master page </span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo2"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">4-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">Define the mastertype directive in page</span></p><div class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo2"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">5-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">You can access masterpage public properties and method through Master object in the page</span></div><div class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; TEXT-ALIGN: center; mso-list: l1 level1 lfo2"><span style="font-family:Calibri;"><a href="http://www.csharpcourses.com-a.googlepages.com/MasterPageAccessSample.zip">download the source code</a></span></div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com4tag:blogger.com,1999:blog-7712731644405234924.post-30323574959178037082008-06-17T08:30:00.002+10:002008-06-17T08:52:11.802+10:00Operators in C#<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><span lang="EN-US" style="mso-bidi-language: FA">It is important to know that C# and java support the rules of IEEE, means if you have 10.5/0 you won't get an error. It will be <i>infinity </i>or if you have 0.0/0.0 the result will be <i>not a number. </i>But if you have 10/0 then you will got an <i>overflow</i> error.</span><b><span lang="EN-US" style="mso-bidi-language: FA;font-size:14;" ></span></b></span></span></p><pre><span lang="EN-US" style="font-family:'Times New Roman','serif';font-size:85%;">As you all know there are different kinds of operators. </span></pre><pre style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt left 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-size:85%;"> <span lang="EN-US" style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbolfont-family:Symbol;" ><span style="mso-list: Ignore">·<span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span lang="EN-US" style="font-family:'Times New Roman','serif';">Relational Operators such as ==,!=,>,>=,<,<= which are used between two operands(except !=) and the result is a Boolean.</span></span></pre><pre style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt left 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-size:85%;"> <span lang="EN-US" style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbolfont-family:Symbol;" ><span style="mso-list: Ignore">·<span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span lang="EN-US" style="font-family:'Times New Roman','serif';">Logical operators such as &,,&&, that are used between two Boolean operands and return a boolean. It is good to point that && and make a short circuit, means if the first operand is false the && operator returns false without checking the other operand. But if the first operand is true operator will return true without checking the other one.</span></span></pre><pre style="MARGIN-LEFT: 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt left 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><span style="font-size:85%;"> <span lang="EN-US" style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbolfont-family:Symbol;" ><span style="mso-list: Ignore">·<span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span lang="EN-US" style="font-family:'Times New Roman','serif';">Arithmetic operators such as +,-,*,%. No need to describe them more as you are familiar with </span></span></pre><pre><span lang="EN-US" style="font-family:'Times New Roman','serif';font-size:85%;"> </span></pre><pre style="MARGIN-LEFT: 18pt"><span lang="EN-US" style="font-family:'Times New Roman','serif';font-size:85%;">Besides the other operators that we don't describe them here, there are some important ones that are basic in C#.</span></pre><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">++ Increment operator, incrementing the value by 1 (i++ is the same as i=i+1)</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">— Decrement operator, decrementing the value by 1 (i— is the same as i=i-1)</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">+= Increment assignment operator (i+=5 is the same as i=i+5)</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">-= Decrement assignment operator (i-=5 is the same as i=i-5)</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">== and != Equality and Inequality operator</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><span lang="EN-US"><span style="font-family:Times New Roman;font-size:100%;">% Modulus (remainder) operator. (17%5 equals 2)</span></span></p><p class="first-para" style="MARGIN: auto 0cm auto 18pt"><strong><span style="font-family:Times New Roman;">Thanks to Azadeh for this post</span></strong></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-5166695056097589352008-06-08T21:17:00.002+10:002008-06-08T21:19:30.499+10:00Evaluate your code by Code Analysis<p class="mobile-photo"><span style="font-family:Calibri;font-size:100%;">We may write lines and lines of code but never check our code to see whether we follow up the best practice for coding. Sometimes, we make big mistakes in our codes it may not appear now but in future when change requests come. It reveals our code was not that much good we thought it was. So how can a programmer be confident about his code? The only way is that you need to review your code but in reality being overloaded we never have this chance. Nevertheless, we need code checking to be automatic and Code Analysis is a tool absolutely free with Visual studio .Net helps us to check our code in terms of security, design, maintainability, reliability and a lot more. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><strong>How to configure Code Analysis?</strong></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Open your project in visual studio then right click on your project and select properties. Then select code analysis tab. And you need to check "Enable Code Analysis". I highly recommend taking a look at different Rules that you can check. For example if you have different naming convention you can unselect that.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-spacerun: yes"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjidXSHu80JgFb8YnoaH7hNtBABlhwG3J6RgJvLtyB6H_aY3iLHnSGTwEE4bbc2yy8kA5dbzfmKcA9WgwNVn_nO469EU2ohJIxNqH8W6HBS7FlRfL8FLgDfoYzqvFBK75uA5DEgAfmZn1E/s1600-h/Snap1-738186.jpg"><img id="BLOGGER_PHOTO_ID_5209468219451087410" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjidXSHu80JgFb8YnoaH7hNtBABlhwG3J6RgJvLtyB6H_aY3iLHnSGTwEE4bbc2yy8kA5dbzfmKcA9WgwNVn_nO469EU2ohJIxNqH8W6HBS7FlRfL8FLgDfoYzqvFBK75uA5DEgAfmZn1E/s320/Snap1-738186.jpg" border="0" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZdahqs54Xpn0WN2JX56QTDUIIqxpbkxmrwTt1219iAFab88RcYZM4xQwxHjkiayZuv9ZX8OO2a4t0jch57LB3IK2Qs-WYUDoi1FC95ra7WWE19Sxau4yscYkpxFIHB1m53R6pyOyij10/s1600-h/Snap2-738839.jpg"></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Then all you need in solution explorer right click on your project and select Run Code Analysis. It will show you some warning for your code.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZdahqs54Xpn0WN2JX56QTDUIIqxpbkxmrwTt1219iAFab88RcYZM4xQwxHjkiayZuv9ZX8OO2a4t0jch57LB3IK2Qs-WYUDoi1FC95ra7WWE19Sxau4yscYkpxFIHB1m53R6pyOyij10/s1600-h/Snap2-738839.jpg"><img id="BLOGGER_PHOTO_ID_5209468216836775810" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZdahqs54Xpn0WN2JX56QTDUIIqxpbkxmrwTt1219iAFab88RcYZM4xQwxHjkiayZuv9ZX8OO2a4t0jch57LB3IK2Qs-WYUDoi1FC95ra7WWE19Sxau4yscYkpxFIHB1m53R6pyOyij10/s320/Snap2-738839.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Take a look at this picture</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1XIbTQ_b2ZrETiwxYdXztYOASxRJhCWtO2qrqq0gWzANjLCJpPTjDcI-k26R_298HdW9xQ-BnXV0Uoc0W51e0C5INkCerzzcTqNGbd28aXvWqYXZ28ihMNU8PiDIeirNZ2CPfQk-nFi4/s1600-h/Snap3-739359.jpg"><img id="BLOGGER_PHOTO_ID_5209468224490768466" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1XIbTQ_b2ZrETiwxYdXztYOASxRJhCWtO2qrqq0gWzANjLCJpPTjDcI-k26R_298HdW9xQ-BnXV0Uoc0W51e0C5INkCerzzcTqNGbd28aXvWqYXZ28ihMNU8PiDIeirNZ2CPfQk-nFi4/s320/Snap3-739359.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">For simple code that I wrote code analysis could find some issues with my code. One of them says for enum value you need to have a zero value which is part of Microsoft best practice.</span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com3tag:blogger.com,1999:blog-7712731644405234924.post-32177176176282291142008-06-08T21:03:00.003+10:002008-06-08T21:12:54.783+10:00Primitive data types in C#<p class="mobile-photo" align="center"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><strong>"Special thanks to Azadeh Hasanzadeh who wrote this fantastic post"</strong></span></span></span></p><p class="mobile-photo"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">The data type variables define the type of data and the format can be stored in it.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">In case of data types we can divide programming languages to 3 groups.</span></span></span></p><ol style="MARGIN-TOP: 0cm" type="1"><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l1 level1 lfo1; tab-stops: list 36.0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Untyped languages: In these languages there is no need to declare the data </span></span></span></li></ol><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">type.For example in javascript when you have a=10, it means "a" is an integer because it is assigned to 10 so the data type is predicted by assignment</span></span></span></p><ol style="MARGIN-TOP: 0cm" type="1" start="2"><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l1 level1 lfo1; tab-stops: list 36.0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Typed languages: You should declare the data type.</span></span></span></li></ol><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">For example in Pascal, C or VB you should declare the data type of a variable to initiate it .In C:</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">char c = 2</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">short s </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">s=c</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">In this example as C is a low level language the HEX values of 2 as a character will be placed in s.</span></span></span></p><ol style="MARGIN-TOP: 0cm" type="1" start="3"><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l1 level1 lfo1; tab-stops: list 36.0pt"><div align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Strongly typed languages: In these languages not only you should declare the data type but also you should be aware of data type conversion. C# is in this category.</span></span></span></div></li></ol><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><span style="mso-spacerun: yes"></span>In C# you will face a compiler error if you try to assign a character in integer type unless you as a programmer accept the responsibility.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Data Types in C#</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">We can summarize primitive data types as the table below</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><table class="MsoNormalTable" style="WIDTH: 70.54%; mso-cellspacing: 1.5pt" cellpadding="0" width="70%" border="1"><thead><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><b><span lang="EN-US"><span style="font-family:Times New Roman;">Data type</span></span></b></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><b><span lang="EN-US"><span style="font-family:Times New Roman;">Description</span></span></b></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><b><span lang="EN-US"><span style="font-family:Times New Roman;">Size (bits)</span></span></b></p></td></tr></thead><tbody><tr style="mso-yfti-irow: 1"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><span style="font-family:Times New Roman;"><i><span lang="EN-US">Byte</span></i><span lang="EN-US"> </span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Unsigned integer</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">8</span></span></p></td></tr><tr style="mso-yfti-irow: 2"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><span style="font-family:Times New Roman;"><i><span lang="EN-US">Short</span></i><span lang="EN-US"> </span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Signed integer</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">16</span></span></p></td></tr><tr style="mso-yfti-irow: 3"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">int</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Whole numbers</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">32</span></span></p></td></tr><tr style="mso-yfti-irow: 4"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">Long</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Whole numbers<span style="mso-spacerun: yes"> </span>(bigger range)</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">64</span></span></p></td></tr><tr style="mso-yfti-irow: 5"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">Float</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Floating-point numbers</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">32</span></span></p></td></tr><tr style="mso-yfti-irow: 6"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">double</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Double-precision </span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">64</span></span></p></td></tr><tr style="mso-yfti-irow: 7"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">Decimal</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Monetary values</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">96</span></span></p></td></tr><tr style="mso-yfti-irow: 8"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">Bool </span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">True, false</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">8</span></span></p></td></tr><tr style="mso-yfti-irow: 9; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 17.64%; PADDING-TOP: 0.75pt" valign="top" width="17%"><p class="table-para" style="MARGIN: auto 0cm"><i><span lang="EN-US"><span style="font-family:Times New Roman;">char</span></span></i></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 60.78%; PADDING-TOP: 0.75pt" valign="top" width="60%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">Single character</span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 19.64%; PADDING-TOP: 0.75pt" valign="top" width="19%"><p class="table-para" style="MARGIN: auto 0cm"><span lang="EN-US"><span style="font-family:Times New Roman;">16</span></span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">As I said above C# is a strongly typed language and data type conversion happens under especial circumstances. It means: smaller data types can be converted to bigger but not the opposite. Let's explain it in an example. There are three variables. One is short, the other is an int and the last one is a long.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">You simply can convert short to int as int data type accepts a wider range of numbers that includes short data type, but you can't convert long to int. unless you accept the responsibility of loss of data that may happen during the data type conversion. This acceptance is known as <i>Cast. </i>Pay extra attention that in casting you will lost the most valuable bytes of data.<i></i></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Do you agree to have all we talked about, in an example in .net environment? Here it is:</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">First of all we will have our examples as a console application which is free from interface.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Let's start together.</span></span></span></p><ol style="MARGIN-TOP: 0cm" type="1"><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">From start menu select <i>Microsoft visual studio 2005.</i></span></span></span></li><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">File/New/Project.</span></span></span></li><li class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo2; tab-stops: list 36.0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Select the options as shown in the figure 1.</span></span></span></li></ol><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3I2CReMxqRXkWzBVrI1u72XbhG1Iu7pgArnOTzQOxhNeuj3Dyne8FPW46uutaO5GCclh02836-Lwx_Ocq0lAN9w5Ed_W2Q19J4O33zKcb_USwq28tuVpdsxGGzD_rNzPSDr26wIMGKwA/s1600-h/Snap5-737107.jpg"><img id="BLOGGER_PHOTO_ID_5209464776532451394" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3I2CReMxqRXkWzBVrI1u72XbhG1Iu7pgArnOTzQOxhNeuj3Dyne8FPW46uutaO5GCclh02836-Lwx_Ocq0lAN9w5Ed_W2Q19J4O33zKcb_USwq28tuVpdsxGGzD_rNzPSDr26wIMGKwA/s320/Snap5-737107.jpg" border="0" /></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="mso-bidi-language: FA"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Figure 1</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Type a Name for your project and browse for its location.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><span lang="EN-US" style="mso-bidi-language: FA">The main window of the .net environment will be shown. In the left pane (solution explorer) you can see "MyfirstProject" as you chose for your project's name. In the source code environment you can also see "MyfirstProject" as the name of the namespace. There is a class named Program. You can change it to whatever you like. The only thing you need to do is select the name of the class from the solution explorer, press F4 or select view/properties windows to see the properties of the class, and then easily change the File Name to your desired name. Pay attention that the class name in source code will be changed. In the "Program" class you are able to see a method called Main which is the main method of the class exactly as it was in C. We will talk about it later.</span><span lang="FA" dir="rtl" style="mso-bidi-language: FA"></span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Imagine we have information of a 30_year_old person whose name is "Matt". The whole days of his age is age*365. Just think that you want to show his Days Of Age in "age" variable. We can declare this information like this:</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >static</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > age;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> name;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">long</span> daysOfAge;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>age = 30;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>name = <span style="color:maroon;">"Matt"</span>;<span style="mso-spacerun: yes"> </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>daysOfAge = age*365;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>age = daysOfAge;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none" align="justify"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;font-size:100%;">If you click run button (</span><span style="font-size:100%;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:100%;"><span style="font-family:Times New Roman;">) or press F5 you will face an error that its explanation is shown in the bottom of the page. This is exactly the case we talked about before.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:10;" ></span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:10;" ><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiO4mWHwB1cIc9KQgpSCqyWEqT9VNwG9XDmvkahtkrgiLLUZFlj0RZZ-HGQ0SmM7eerq9_OkBPSmOR8QzPGCN7QC66MXSmP38siZ-aPicTHl84OkhSuoJCq_MlghQDOH_b8VN8V8-4dQU/s1600-h/Snap6-738145.jpg"><img id="BLOGGER_PHOTO_ID_5209464784985260306" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiO4mWHwB1cIc9KQgpSCqyWEqT9VNwG9XDmvkahtkrgiLLUZFlj0RZZ-HGQ0SmM7eerq9_OkBPSmOR8QzPGCN7QC66MXSmP38siZ-aPicTHl84OkhSuoJCq_MlghQDOH_b8VN8V8-4dQU/s320/Snap6-738145.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align="center"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Figure 2</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align="center"><span style="font-family:Times New Roman;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">You can see that the compiler can't convert long to int. The interesting thing is that it suggests you Casting the data types.(are you missing a cast?)</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">If you change the above code snippet to </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >static</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 36pt; mso-layout-grid-align: none"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >int</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > age;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> name;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">long</span> daysOfAge;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>age = 30;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>name = <span style="color:maroon;">"Matt"</span>;<span style="mso-spacerun: yes"> </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>daysOfAge = age*365;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>age =<span style="color:teal;">Convert</span>.ToInt32 (daysOfAge ) ;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><span style="font-family:Courier New;font-size:85%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Then you will say to the compiler that you are aware of possible loss of data. So that compiler won't have any responsibility against this matter.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">This is the complete code for our first project. Just type it as it is in figure 3. Don't worry about the syntax you don't know about. We will discuss about them later.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Running a project in .net is with F5 and it start debugging the project, but if you do that you will see that the result is shown so quick that you may not be able to see it. So ctrl+F5 (start without debugging) will give you the chance to see the result.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX6u1pxvKgQxD08g3qaTU2SUQVdAvPsoSjvnLywJGnE8U4waKsk4mzd-T6E-EXjvMpIFsCxUB9-SMlwK62OvYU-ku_DsO1yZSRmyfG5bKoo6TaOuyotSarghF_WkPUmRj9OgJVWkH2-TQ/s1600-h/Snap7-739760.jpg"><img id="BLOGGER_PHOTO_ID_5209464786411739378" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX6u1pxvKgQxD08g3qaTU2SUQVdAvPsoSjvnLywJGnE8U4waKsk4mzd-T6E-EXjvMpIFsCxUB9-SMlwK62OvYU-ku_DsO1yZSRmyfG5bKoo6TaOuyotSarghF_WkPUmRj9OgJVWkH2-TQ/s320/Snap7-739760.jpg" border="0" /></a></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Figure 3</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><b><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Note:</span></span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;"><span style="mso-spacerun: yes"></span>There is point about decimal and float data types in C#. In C# every floating numbers are known as double. If you write double d = 10.5; you won't face any error. But if you write float f = 10.5 you will get error. That's because default data type of floating numbers is double and you are trying to cast a double to a float which is a smaller data type and as I explained before changing a data type to a smaller needs to accept the responsibility of loss of data that we called it casting. To avoid this error there are some <i>literals </i>that <i>f</i> is used for casting to float and m is used for casting to decimal data types. It means that you can easily use f as a key word to cast a data type to float which is preferable than using cast. For example </span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >float</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > d = 10.5f;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">means you are emphasizing that 10.5 is a float.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="justify"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-size:100%;"><span style="font-family:Times New Roman;">Double and float data types round the digit and you can't have precision. So using decimal data type will solve this problem which doesn't round the digit. To convert a digit to decimal you can simply use <i>m </i>literal instead of casting.</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-bidi-language: FA"><span style="font-family:Times New Roman;font-size:100%;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size:85%;"><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >decimal</span><span lang="EN-US" style="mso-no-proof: yes;font-family:'Courier New';" > d = 10.5m;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US" style="mso-no-proof: yes"><span style="font-family:Times New Roman;font-size:100%;">This shows that you are using d as a decimal value not a double.</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-family:Times New Roman;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt" align="center"><span style="font-family:Times New Roman;"></span><span lang="EN-US" style="mso-bidi-language: FA"><strong>"Special thanks to Azadeh Hasanzadeh who wrote this fantastic post"</strong></span></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-17208859261331169192008-06-05T22:48:00.002+10:002008-06-05T22:52:49.795+10:00How to export data to CSV file in ASP.NET<p class="mobile-photo" align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/ExportToCSV.zip">Download the source code</a></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">First let's see what the CSV file is:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">CSV file is a text based file in which data are separated by comma. It can be opened by excel so you can use excel functionality. Each row of data including the title is in separate line. Meanwhile, each row has data separated by comma.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">How to create a CSV file?</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">We need to write data to Response object. Meanwhile the content type should be text/csv also a header type of attachment should be added to response. Afterwards, column names are written to response then to actual data is written (each row should be just in one line).Finally you need to call Response.End to finalize your work.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">Important: if any part of data has comma, unfortunately the CSV file will be screwed up. What I did in the code is that I am replacing comma with space so I am sure that the only comma exists in each row is just for separating data rather than being part of data.</span></span></b></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >public</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">class</span> <span style="color:#2b91af;">CSVExporter</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >{</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> WriteToCSV(<span style="color:#2b91af;">List</span><<span style="color:#2b91af;">Person</span>> personList)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">string</span> attachment = <span style="color:#a31515;">"attachment; filename=PerosnList.csv"</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.Clear();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.ClearHeaders();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.ClearContent();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.AddHeader(<span style="color:#a31515;">"content-disposition"</span>, attachment);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.ContentType = <span style="color:#a31515;">"text/csv"</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.AddHeader(<span style="color:#a31515;">"Pragma"</span>, <span style="color:#a31515;">"public"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>WriteColumnName();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">foreach</span> (<span style="color:#2b91af;">Person</span> item <span style="color:blue;">in</span> personList)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>WriteUserInfo(item);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.End();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> WriteUserInfo(<span style="color:#2b91af;">Person</span> item)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">StringBuilder</span> strb = <span style="color:blue;">new</span> <span style="color:#2b91af;">StringBuilder</span>();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>AddComma(item.Name, strb);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>AddComma(item.Family, strb);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>AddComma(item.Age.ToString(), strb);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>AddComma(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"{0:C2}"</span>, item.Salary), strb);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.Write(strb.ToString());</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.Write(<span style="color:#2b91af;">Environment</span>.NewLine);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span> </p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> AddComma(<span style="color:blue;">string</span> item, <span style="color:#2b91af;">StringBuilder</span> strb)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>strb.Append(item.Replace(<span style="color:#a31515;">','</span>, <span style="color:#a31515;">' '</span>));</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>strb.Append(<span style="color:#a31515;">" ,"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> WriteColumnName()</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:blue;">string</span> str = <span style="color:#a31515;">"Name, Family, Age, Salary"</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.Write(str);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span><span style="color:#2b91af;">HttpContext</span>.Current.Response.Write(<span style="color:#2b91af;">Environment</span>.NewLine);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"> </span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >}</span></p></td></tr></tbody></table><p align="center"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY5LyWE04cqjqKLsgQyNApbrhkyTiUVGPMwO71p0gPCooeUHxouDfJWCEq2xE59N6DdLMb9z6QwxOiJAkRPTouaUUV1BIQ1PN4ydaLqUw7pPWMtm9x5mBFbrJxtTwFMuzI-utGe6zBjpg/s1600-h/Snap1-711415.jpg"><img id="BLOGGER_PHOTO_ID_5208378471217267346" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY5LyWE04cqjqKLsgQyNApbrhkyTiUVGPMwO71p0gPCooeUHxouDfJWCEq2xE59N6DdLMb9z6QwxOiJAkRPTouaUUV1BIQ1PN4ydaLqUw7pPWMtm9x5mBFbrJxtTwFMuzI-utGe6zBjpg/s320/Snap1-711415.jpg" border="0" /></a></span></p><p align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/ExportToCSV.zip">Download the source code</a></p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com11tag:blogger.com,1999:blog-7712731644405234924.post-73985986048294611212008-06-05T06:00:00.003+10:002008-06-05T06:35:40.203+10:00How to pass parameters to Reporting Services from .Net applications<div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: center"><span style="font-family:Calibri;"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServicesPassPrameterfromAs.html')" href="http://www.csharpcourses.com/2008/06/how-to-pass-parameters-to-reporting.html">please see the clip</a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">In the previous post you saw how to create a report in reporting services and you also learned how to create parameter for the report. You simple can show the same report and you do not need to pass parameter since everything is inside the report. But unfortunately you cannot change the UI of State dropdownlist or View Report button. So you may want to remove this parameter palette and show this information in another custom control then pass the information to reporting service. </span></div><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">First add a dropdownlist to the page that has the states and also a report viewer control and a button to trigger to show the report. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">Add all states on the dropdownlist either by loading information from database or adding them manually. Then on button click please write this code</span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ShowCredentialPrompts = <span style="color:blue;">false</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ServerReport.ReportServerCredentials = <span style="color:blue;">new</span> <span style="color:#2b91af;">ReportCredentials</span>(<span style="color:#a31515;">"emady"</span>, <span style="color:#a31515;">"MyPassword"</span>, <span style="color:#a31515;">"hhi"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ServerReport.ReportServerUrl = <span style="color:blue;">new</span> <span style="color:#2b91af;">Uri</span>(<span style="color:#a31515;">"<a href="http://falcon/Reportserver">http://falcon/Reportserver</a>"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ServerReport.ReportPath = <span style="color:#a31515;">"/Report Project State/Report1"</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;"><span style="color:#2b91af;">List</span><<span style="color:#2b91af;">ReportParameter</span>> parameters = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span><<span style="color:#2b91af;">ReportParameter</span>>();</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">parameters.Add(<span style="color:blue;">new</span> <span style="color:#2b91af;">ReportParameter</span>(<span style="color:#a31515;">"state"</span>, DropDownListStates.SelectedItem.Text));</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ServerReport.SetParameters(parameters);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes;font-size:85%;" ></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ProcessingMode = <span style="color:#2b91af;">ProcessingMode</span>.Remote;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ShowParameterPrompts = <span style="color:blue;">false</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ShowPromptAreaButton = <span style="color:blue;">false</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="mso-spacerun: yes"></span><span style="font-size:85%;">ReportViewer1.ServerReport.Refresh();</span></span></p></td></tr></tbody></table><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-spacerun: yes"><span style="font-family:Calibri;"></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;">The only change that you may see compare to what we had in previous clip is that:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;">We set that we do not want seeing any credentials error prompt. Moreover, we create a list of ReportParameter and add the state parameter to this list and we are passing this list to SetParameter method. Also we are hiding parameter part from report. Finally we are hiding any prompt from report server.</span></p><p><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-bidi-: minor-bidifont-family:'Times New Roman';" >Important: ReportCredentials class is a custom class please get the code from previous posts about reporting services. Also please see the clip to understand how it works.</span></p><p align="center"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServicesPassPrameterfromAs.html')" href="http://www.csharpcourses.com/2008/06/how-to-pass-parameters-to-reporting.html">please see the clip</a> </p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com13tag:blogger.com,1999:blog-7712731644405234924.post-25868730781007613882008-06-03T06:33:00.003+10:002008-06-03T06:40:11.255+10:00How to create a parameterized report with Reporting Services<p class="mobile-photo" align="center"><span style="font-family:Calibri;font-size:100%;"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServiceParameter.html')" href="http://www.csharpcourses.com/2008/06/how-to-create-parameterized-report-with.html">please see the clip</a></span></p><p class="mobile-photo" align="justify"><span style="font-family:Calibri;font-size:100%;">I assuming you have already read the previous posts about Reporting Services and you familiar with creating report. Let's say you have the same project in previous post. And you need to show just post code information that is in just one specific State. I am going to explain how to create a state parameter. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Open the report then go to Data View and select"New DataSet..."</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgmL_5_h3e36voH40X7GfvTDHWD_vCExFd07R9kQr9YOzvYk7Yr_6J8EOkMykxb4jOXqvHXpoVyksP7CX6TWZUCiCnaLKdHtRAjqUndWeew27jreLHtJi576ZW1BZjpXPts58tY7oeAOw/s1600-h/Snap3-733143.jpg"><img id="BLOGGER_PHOTO_ID_5207385139770982978" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgmL_5_h3e36voH40X7GfvTDHWD_vCExFd07R9kQr9YOzvYk7Yr_6J8EOkMykxb4jOXqvHXpoVyksP7CX6TWZUCiCnaLKdHtRAjqUndWeew27jreLHtJi576ZW1BZjpXPts58tY7oeAOw/s320/Snap3-733143.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">Then all you need write a query to show all the states like this:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi07ZjF34hyWxDraWDXLmNmQBTNjmIekIvHzJo2R1TFw69jmr2MjECnXoEykG4OFKCBa6mIzSTLB6SP8xZugsH5RwPLYVmKtxN7H-FRsOJSJG_rncsb2Sn63WYouEK5dgQD-Bdp7f1VQL0/s1600-h/Snap4-734101.jpg"><img id="BLOGGER_PHOTO_ID_5207385174130721362" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi07ZjF34hyWxDraWDXLmNmQBTNjmIekIvHzJo2R1TFw69jmr2MjECnXoEykG4OFKCBa6mIzSTLB6SP8xZugsH5RwPLYVmKtxN7H-FRsOJSJG_rncsb2Sn63WYouEK5dgQD-Bdp7f1VQL0/s320/Snap4-734101.jpg" border="0" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho02HcNd_bgHaOuNfBLp1nTQPune1PFAXdb6NShT9u8x0-pVnR7iGmz5pfwKfXagsCjeZrvkO_R5DCyMnHLU1T6ouq_fRowpzHoxuNpuhoXHOzPfLmbZDL-8Rp8-7reHVeJS-xQdIROOQ/s1600-h/Snap5-742497.jpg"></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Then Select the previous data source and change the query as below. Remember when<span style="mso-spacerun: yes"> </span>your query has some parameters (in reporting service @variable is a parameter) it will be automatically added to Report Parameters</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho02HcNd_bgHaOuNfBLp1nTQPune1PFAXdb6NShT9u8x0-pVnR7iGmz5pfwKfXagsCjeZrvkO_R5DCyMnHLU1T6ouq_fRowpzHoxuNpuhoXHOzPfLmbZDL-8Rp8-7reHVeJS-xQdIROOQ/s1600-h/Snap5-742497.jpg"><img id="BLOGGER_PHOTO_ID_5207385178425688674" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho02HcNd_bgHaOuNfBLp1nTQPune1PFAXdb6NShT9u8x0-pVnR7iGmz5pfwKfXagsCjeZrvkO_R5DCyMnHLU1T6ouq_fRowpzHoxuNpuhoXHOzPfLmbZDL-8Rp8-7reHVeJS-xQdIROOQ/s320/Snap5-742497.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">So this query will need a state to run. From Report menu select Report Parameters you need to select "From query" radio button from "Available values" and also set the default value. As below (for more information see the clip)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIXDJbT2NCg3SgSKjO69_LtrAzxIHxaelBDkCBEuxaVa_ROXrgVWJPDjBXrtu66mhmRTDk797OBoHxLbrDN8xQtmIDpPBxXjNryP5R_E2cSDBPe-0UtnamfepGa5kbKCgL97wD3WpEjB0/s1600-h/Snap6-744470.jpg"><img id="BLOGGER_PHOTO_ID_5207385187015623282" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIXDJbT2NCg3SgSKjO69_LtrAzxIHxaelBDkCBEuxaVa_ROXrgVWJPDjBXrtu66mhmRTDk797OBoHxLbrDN8xQtmIDpPBxXjNryP5R_E2cSDBPe-0UtnamfepGa5kbKCgL97wD3WpEjB0/s320/Snap6-744470.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;">The result should be like this:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUHOyiHPJxXgIrO3TKst4Kq5hZH5P-YqVsiQeWMeVwU6v_V0iEXwpHyrTNOC5GnlkqDb8RW3de5uC24G5zqIb8pDJNU36i6AGlrhWnHt8hAD87uymuIIFewrQOSnO-zx3JtQaCEN4Tf7g/s1600-h/Snap8-746286.jpg"><img id="BLOGGER_PHOTO_ID_5207385195605557890" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUHOyiHPJxXgIrO3TKst4Kq5hZH5P-YqVsiQeWMeVwU6v_V0iEXwpHyrTNOC5GnlkqDb8RW3de5uC24G5zqIb8pDJNU36i6AGlrhWnHt8hAD87uymuIIFewrQOSnO-zx3JtQaCEN4Tf7g/s320/Snap8-746286.jpg" border="0" /></a></span></p><p align="center"><br /><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServiceParameter.html')" href="http://www.csharpcourses.com/2008/06/how-to-create-parameterized-report-with.html">please see the clip</a> </p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0tag:blogger.com,1999:blog-7712731644405234924.post-69592658448627159992008-06-02T07:08:00.003+10:002008-06-02T07:17:12.729+10:00How to show a report of reporting services from .net applications<div align="center"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServiceShow.html');" href="http://www.csharpcourses.com/2008/06/how-to-show-report-of-reporting.html">please see the clip</a> </div><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify" align="center"><span style="font-family:Calibri;font-size:100%;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify" align="center"><span style="font-family:Calibri;font-size:100%;">After deploying your reports to report server, you need to access these reports and show them in your custom .net applications. This post will help you to do this task. Please see the clip that shows you how to deploy your report and how to access them.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:Calibri;font-size:100%;">Let's say you have a web application that needs to show reports. Firstly, you need add the ReportViewer control from toolbox (which is in data tab) to your page. Then you need to write some code to load report inside the ReportViewer probably you write this code either in page load or in a button click.<span style="mso-spacerun: yes"> </span>Take a look to this code:</span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ServerReport.ReportServerCredentials = <span style="color:blue;">new</span> <span style="color:#2b91af;">ReportCredentials</span>(<span style="color:#a31515;">"emady"</span>, <span style="color:#a31515;">"mypassword"</span>, <span style="color:#a31515;">"hhi"</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ServerReport.ReportServerUrl = <span style="color:blue;">new</span> <span style="color:#2b91af;">Uri</span>(<span style="color:#a31515;">"<a href="http://falcon/Reportserver">http://falcon/Reportserver</a>"</span>);</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ServerReport.ReportPath = <span style="color:#a31515;">"/Report Project State/Report1"</span>;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ProcessingMode = <span style="color:#2b91af;">ProcessingMode</span>.Remote;</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" >ReportViewer1.ServerReport.Refresh();</span></p></td></tr></tbody></table><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:Calibri;">The first line is trying to pass the credentials to server. Second line is the Reportserver address. Third line specifies the Report address which has Report folder address and the report itself. Forth line sets the processing mode to Remote because you are accessing the report from other application. Finally you need to call Refresh to show the report.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:Calibri;">The very tricky part about above code is that I used a Custom class Called ReportCredentials to apply my credentials to the Report server. The reality is that you need a valid credential to access report server so you need to pass this credential by this class which is inherited from IReportServerCredentials. Take a look at the source of this class: </span></p><table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid black .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-theme: 1184color:text1;" cellspacing="0" cellpadding="0" border="1" ><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: black 1pt solid; WIDTH: 462.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid black .5ptcolor:text1;" valign="top" width="616" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size:85%;"><span style="mso-no-proof: yes;font-family:'Courier New';color:blue;" >public</span><span style="mso-no-proof: yes;font-family:'Courier New';" > <span style="color:blue;">class</span> <span style="color:#2b91af;">ReportCredentials</span> : Microsoft.Reporting.WebForms.<span style="color:#2b91af;">IReportServerCredentials</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">string</span> _userName, _password, _domain;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> ReportCredentials(<span style="color:blue;">string</span> userName, <span style="color:blue;">string</span> password, <span style="color:blue;">string</span> domain)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>_userName = userName;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>_password = password;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>_domain = domain;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> System.Security.Principal.<span style="color:#2b91af;">WindowsIdentity</span> ImpersonationUser</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">get</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">null</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> System.Net.<span style="color:#2b91af;">ICredentials</span> NetworkCredentials</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">get</span></span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">new</span> System.Net.<span style="color:#2b91af;">NetworkCredential</span>(_userName, _password, _domain);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">public</span> <span style="color:blue;">bool</span> GetFormsCredentials(<span style="color:blue;">out</span> System.Net.<span style="color:#2b91af;">Cookie</span> authCoki, <span style="color:blue;">out</span> <span style="color:blue;">string</span> userName, <span style="color:blue;">out</span> <span style="color:blue;">string</span> password, <span style="color:blue;">out</span> <span style="color:blue;">string</span> authority)</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>{</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>userName = _userName;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>password = _password;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>authority = _domain;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';font-size:85%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>authCoki = <span style="color:blue;">new</span> System.Net.<span style="color:#2b91af;">Cookie</span>(<span style="color:#a31515;">".ASPXAUTH"</span>, <span style="color:#a31515;">".ASPXAUTH"</span>, <span style="color:#a31515;">"/"</span>, <span style="color:#a31515;">"hhi"</span>);</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal"><span style="mso-no-proof: yes;font-family:'Courier New';" ><span style="font-size:85%;"><span style="mso-spacerun: yes"></span>}</span></span></p></td></tr></tbody></table><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;font-size:85%;"></span></p><div align="center"><br /><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServiceShow.html');" href="http://www.csharpcourses.com/2008/06/how-to-show-report-of-reporting.html">please see the clip</a></div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com2tag:blogger.com,1999:blog-7712731644405234924.post-30642118223791955872008-05-31T18:21:00.004+10:002008-05-31T19:03:53.312+10:00Create a report with Reporting services<p class="mobile-photo" align="center"><span style="font-size:100%;"><span style="font-family:Calibri;"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServices.html');" href="http://www.csharpcourses.com/2008/05/create-report-with-reporting-services.html">See the clip</a></span></span></p><p class="mobile-photo"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">What is Reporting Service?</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;font-size:100%;">Reporting service is a free application coming with sqlserver so if you have sql server in your organization then probably you have Reporting service as well. It is a repository for your reports you can create reports by some tools then publish your report to this repository then your applications including windows and web can send request to this repository and get the report in a browser. Since you can create complex report to show different charts and graphs, it is one of the handy tools to use specially in Intranet web applications. Also you can use reporting service for internet applications However, you will be charged for that.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;"><span style="font-family:Calibri;">What do you need to know about Reporting services?</span></span></b></p><p class="MsoListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">1-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to create a report </span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">2-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to publish a report</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">3-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to see the report in the server</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">4-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to access a report from other .net applications (Next post)</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">5-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to create a chart report (there is a sample in clip)</span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">6-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;font-size:100%;">How to create a parameterized report (future posts)</span></p><p class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="mso-bidi-: minor-latin;font-family:Calibri;" ><span style="mso-list: Ignore"><span style="font-family:Calibri;font-size:100%;">7-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:Calibri;">How to pass parameters to a report from other applications (future posts)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-family:Calibri;">How to create a report?</span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;"><span style="mso-spacerun: yes"></span>When you install sqlserver2005 you have a special template will be added to your visual studio which is "Sql server Business intelligence development studio". You can use this template to create a report then as I explained you have to publish your report then other applications can address that report. Open visual studio from file menu select New Project then you can select Business intelligence project. In this list you can find Report server project wizard or Report Server project. Using Wizard help you to speed up implementation of you report.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimeVH3urAy9ZnyH5uxf3m-FZ6v79y5fiMFUY353t62guLNrAXZod5KXbxpvzD3xoK7C20ami2WhI4f0F-b0zHU0rvOd-SwuAgV8FSqwPvw4YLuAvPXWsD2lldcf9Omeyw6ZV8NtfknmIs/s1600-h/Snap1-711129.jpg"><img id="BLOGGER_PHOTO_ID_5206454325868659026" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimeVH3urAy9ZnyH5uxf3m-FZ6v79y5fiMFUY353t62guLNrAXZod5KXbxpvzD3xoK7C20ami2WhI4f0F-b0zHU0rvOd-SwuAgV8FSqwPvw4YLuAvPXWsD2lldcf9Omeyw6ZV8NtfknmIs/s320/Snap1-711129.jpg" border="0" /></a></span></p><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-family:Calibri;"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" >Let's select Report Server Project. As you see in solution explorer you have two folders one is shared data source and another one is Reports. You need a connection to Database in Reporting service we call that Data source. But if you have multiple reports over one data base you better create one Shared data source to share between them. Because if database changed then you need just change shared data source and everything should be all right. The reports folder is where you create your Reports. I recommend you to use wizard to create the basics of your report then change report to the way you like.</span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:Calibri;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJUf_LEnz23R2K3X67cgsFLGKi_tOkTQKcaa_9etWgbOHUUZDNMqSb_WCi77N3iAbdqAEjR-bikdGAMfufvlrL4ipyS22vmsqpTIIi9ItSSWNG6lomVxbMDmjr_82Z_YXjA5sRO9U_2L8/s1600-h/Snap3-721909.jpg"><img id="BLOGGER_PHOTO_ID_5206454373113299314" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJUf_LEnz23R2K3X67cgsFLGKi_tOkTQKcaa_9etWgbOHUUZDNMqSb_WCi77N3iAbdqAEjR-bikdGAMfufvlrL4ipyS22vmsqpTIIi9ItSSWNG6lomVxbMDmjr_82Z_YXjA5sRO9U_2L8/s320/Snap3-721909.jpg" border="0" /></a></span></div><span style="font-family:Calibri;font-size:100%;"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;">Create a share data source:</span></b></p><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >Right click on Shared Data sources folder and select Add new data source then you will see this window:</span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZNQjbdGefk3-e3R4hyphenhyphent3N-9zy-eDJEKJsex4hL_nNpGynp1lsQGINJw8_Rr2jCua2yo-3yXcx0UuPj9n7Ds60f1jVaOcGBfVAPbYa1KpznNZyEQ_mYLlpC9QL05w9LsIhkwaH7k0ONf0/s1600-h/Snap5-722268.jpg"><img id="BLOGGER_PHOTO_ID_5206454373113299330" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZNQjbdGefk3-e3R4hyphenhyphent3N-9zy-eDJEKJsex4hL_nNpGynp1lsQGINJw8_Rr2jCua2yo-3yXcx0UuPj9n7Ds60f1jVaOcGBfVAPbYa1KpznNZyEQ_mYLlpC9QL05w9LsIhkwaH7k0ONf0/s320/Snap5-722268.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >All you need to do provide an alias name for the shared data source and a correct connection string. The connection string implies to which data base shared data source can connect. You may click on Edit then you will see a familiar window to define a connection string. You can use windows or sql server authentication. Then click on ok. You are done. Now you have a shared data source that can be used in different reports in your project.</span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOslb2BS5oTOD2XmIgq0QpGttgR7zy5Uwfl6hJufnUxxzEk92P_sn1UmgDX1cFFxN15KC11zSr7HL-nmLwrWJ3hWXRit82I3vIjvtAAU-FKPDyzCL_yCBvIA2S2tQHiF041KHIXixZme4/s1600-h/Snap6-722597.jpg"><img id="BLOGGER_PHOTO_ID_5206454373113299346" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOslb2BS5oTOD2XmIgq0QpGttgR7zy5Uwfl6hJufnUxxzEk92P_sn1UmgDX1cFFxN15KC11zSr7HL-nmLwrWJ3hWXRit82I3vIjvtAAU-FKPDyzCL_yCBvIA2S2tQHiF041KHIXixZme4/s320/Snap6-722597.jpg" border="0" /></a></span></div><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-size:100%;">How to create a report?</span></b></p><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >All you need right click on Reports and select Add New Report then you will see the wizard window. As I said you better use wizard then customize your report the way you like later on. (I am going to take a report from a table that has suburbs, postcodes, states)</span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbfBMuqBC8nnYIr5Qfqv9LHY2XvXLwE696lxyjsUJXSDudKqZ300L3mxPRmTOjVVIBICspXK1cF61yPgMZFcYGH-bw1T4rq-FC-mguOxxOzDsdlkvp5XxS0xfwOVw7U4msLr1ZMdMex0U/s1600-h/Snap2-719909.jpg"><img id="BLOGGER_PHOTO_ID_5206454360228397410" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbfBMuqBC8nnYIr5Qfqv9LHY2XvXLwE696lxyjsUJXSDudKqZ300L3mxPRmTOjVVIBICspXK1cF61yPgMZFcYGH-bw1T4rq-FC-mguOxxOzDsdlkvp5XxS0xfwOVw7U4msLr1ZMdMex0U/s320/Snap2-719909.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >Click on next in next page select the shared data source as you see you can select a custom data source but I do not recommend this. Using shared data source is more maintainable.</span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp4siDbkYvbYpUCpdAd48wtFHKrGbLP-mcWMq0b3rkAaMFoAjtpUcgEnGIqeLUZ9HVvTpTM2BA_CTHWRF_xGXwwfMiblAx9Gp_w_wRGL8FQrrQlm60_sdkCctDE0-8tsyOSjWz-EnPn-Y/s1600-h/Snap7-722958.jpg"><img id="BLOGGER_PHOTO_ID_5206454377408266658" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhp4siDbkYvbYpUCpdAd48wtFHKrGbLP-mcWMq0b3rkAaMFoAjtpUcgEnGIqeLUZ9HVvTpTM2BA_CTHWRF_xGXwwfMiblAx9Gp_w_wRGL8FQrrQlm60_sdkCctDE0-8tsyOSjWz-EnPn-Y/s320/Snap7-722958.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >In Next step you need to define your query in our case we are retrieving data from a table but you can retrieve data form view as well. If you take a look at the next picture you will see the query builder button when you go to that page in left top corner of window there is a button which is generic query designer then you can add the tables and views you want and define the query with query designer assistance.</span></span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNE_glI8FXe9Ki9lb9Y-TY4N7wQKlfXYC0C7lAW4MEZklXJoY1uZuxeN_JLEU72odg0QPue9F1M7Xc0lEUjq-ONxItBbCDs9xE80pvbszSqmBDP6Pu2liMlkrMU1eLBQ6ai0a9p9aU-Z0/s1600-h/Snap8-723611.jpg"><img id="BLOGGER_PHOTO_ID_5206454377408266674" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNE_glI8FXe9Ki9lb9Y-TY4N7wQKlfXYC0C7lAW4MEZklXJoY1uZuxeN_JLEU72odg0QPue9F1M7Xc0lEUjq-ONxItBbCDs9xE80pvbszSqmBDP6Pu2liMlkrMU1eLBQ6ai0a9p9aU-Z0/s320/Snap8-723611.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >In next step you need to define your report type in our case we want Tabular:</span></span></span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhujbG7ioGOfQ9j30pDUiRpOAYY_n-Vk5C8VPRn1A3QtLGVADN8y1Oqwaxa09riQqyQwGDCRNGP5BSpfOav6L75FyaR3W2RlnYsFHf4axhvSw7rCTU_bhemPswXcF1hnUQlgQ3e6TZRjDM/s1600-h/Snap9-724233.jpg"><img id="BLOGGER_PHOTO_ID_5206454381703233986" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhujbG7ioGOfQ9j30pDUiRpOAYY_n-Vk5C8VPRn1A3QtLGVADN8y1Oqwaxa09riQqyQwGDCRNGP5BSpfOav6L75FyaR3W2RlnYsFHf4axhvSw7rCTU_bhemPswXcF1hnUQlgQ3e6TZRjDM/s320/Snap9-724233.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >In next step you have the ability to define which fields you need to show in report also you can define group by to show details of one product (please see the clip to see a sample of this) right now we just choose the fields we want to have in our report.</span></span></span></span></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5ZkhvjHD-1TdAkEbdhDrAYpl2Obv56Qp2WnOSEP-jo4haGeudG6_9gZ9Y31LL2gLIUK9MA8BapdozsL4IjAdoWtqirDtnqIyfEyLWkKi92hssKgAewT_rYxbIdVhpfzIaxQx-BSCOv3s/s1600-h/Snap10-724641.jpg"><img id="BLOGGER_PHOTO_ID_5206454381703234002" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5ZkhvjHD-1TdAkEbdhDrAYpl2Obv56Qp2WnOSEP-jo4haGeudG6_9gZ9Y31LL2gLIUK9MA8BapdozsL4IjAdoWtqirDtnqIyfEyLWkKi92hssKgAewT_rYxbIdVhpfzIaxQx-BSCOv3s/s320/Snap10-724641.jpg" border="0" /></a></span></div><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:100%;" >Select a style for your Report and click on next you are done</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVIAwWhhGBUJWW38Lwaz2dBMMacIFmO6DnnmfoGRmNSC7EHi25HsAb7QXDaznEMIO_CTEMPS6XKdEEPIUTmh3c7ujj7CI9AcRLpk_HZom6KpvR6qkZKzUO4nWI5yTVDnRTIv71VMhG3-o/s1600-h/Snap11-725629.jpg"><img id="BLOGGER_PHOTO_ID_5206454385998201314" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVIAwWhhGBUJWW38Lwaz2dBMMacIFmO6DnnmfoGRmNSC7EHi25HsAb7QXDaznEMIO_CTEMPS6XKdEEPIUTmh3c7ujj7CI9AcRLpk_HZom6KpvR6qkZKzUO4nWI5yTVDnRTIv71VMhG3-o/s320/Snap11-725629.jpg" border="0" /></a></span></p><span style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-fareast-language: EN-US; mso-ansi-language: EN-AU; mso-bidi-language: AR-SA; mso-fareast-: minor-latinfont-family:Calibri;font-size:11;" ><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">You have three views: Data, Layout and Preview</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">In the Data view you can see and modify your query also you can add other queries you may use in the report (I will explain how to add another query for this report and why you may need to do that in future posts)</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">In layout you can change look and feel of your report or add other element please see your toolbox when you are in this view then you will see these elements (I will talk about some of these elements in next posts):</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkpo8RzCGgviInCBusyeCxVWprYA1VW3xVW8FxOHBP5qDsGqJQGoiOLo93h342v-i_nBe-D39uShhF4xce7N4hvX-WjsGC9Vrd_B_8EpY2OSnvPpT2Nnqydova5QPqqew9nse_TavZgAc/s1600-h/Snap13-726203.jpg"><img id="BLOGGER_PHOTO_ID_5206454390293168626" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkpo8RzCGgviInCBusyeCxVWprYA1VW3xVW8FxOHBP5qDsGqJQGoiOLo93h342v-i_nBe-D39uShhF4xce7N4hvX-WjsGC9Vrd_B_8EpY2OSnvPpT2Nnqydova5QPqqew9nse_TavZgAc/s320/Snap13-726203.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-size:100%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">In the Preview tab you can see the result which is your report. </span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">How to publish a report to reporting server</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">Next step is that you need to publish you report to Reporting Server to do this you need to right click on your project in solution explorer and select properties. Then you need define 4 properties at least:</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">TargetServerUrl: the reportserver address usually it is the same server as your sqlserver with report server virtual directory see the picture</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">TargetRootFolder: define in which folder the report should be deployed in your reporting server</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">TargetDatasourceFolder: define in which folder the data sources should be deployed in your reporting server</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">OverwriteDataSources: define whether you prefer to overwrite previous deployed data sources.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">I highly recommend specify the same folder for TargetRootFolder and TargetDatasourceFolder because if you are getting Reporting services for an internet site from a shared reporting services in internet you will be offered just one folder so you need to have all of them in one folder.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAhBzy6WmieTGo3kOLQvdi5cVBCVlj6jRwL_kMSlqxWdBkwNVhmZjDw2piAdc4O8bOPXlLEq4zdVidgGsCvppyhHC1S4TsWPuR2mDceE3j3JOSKddllhsExcLPXHiGQxdxwd_gPPrH-S0/s1600-h/Snap14-727327.jpg"><img id="BLOGGER_PHOTO_ID_5206454394588135938" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAhBzy6WmieTGo3kOLQvdi5cVBCVlj6jRwL_kMSlqxWdBkwNVhmZjDw2piAdc4O8bOPXlLEq4zdVidgGsCvppyhHC1S4TsWPuR2mDceE3j3JOSKddllhsExcLPXHiGQxdxwd_gPPrH-S0/s320/Snap14-727327.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">Click on ok again right click on your project select deploy then after a while it will be deployed to the server.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">How to check report in your server?</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt" align="justify"><span style="font-size:100%;">Go to your reporting service through a browser like this: </span><a href="http://yourserver/Reportingserver"><span style="font-size:100%;">http://yourserver/Reportingserver</span></a><span style="font-size:100%;"> in my case I have to use </span><a href="http://falcon/Reporingserver"><span style="font-size:100%;">http://falcon/Reporingserver</span></a><span style="font-size:100%;"> then in that page find the folder in my case TestProjectReport then you will see all reports in that folder select your report in my case Report1<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe71gYiy3izRWLPMJEJVpsvvMItt-Y3px_vIgZqCLpBY65Dx5Wn8t1YgCVt6Tx_vLyiqCnH8TTTQK1jY9KwIO6YSvwQ9ytd23NvopR3_2j9WULoyc-8BL8Vuv-4UcapShcQsPr7PIYeo8/s1600-h/Snap15-727667.jpg"><img id="BLOGGER_PHOTO_ID_5206454394588135954" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe71gYiy3izRWLPMJEJVpsvvMItt-Y3px_vIgZqCLpBY65Dx5Wn8t1YgCVt6Tx_vLyiqCnH8TTTQK1jY9KwIO6YSvwQ9ytd23NvopR3_2j9WULoyc-8BL8Vuv-4UcapShcQsPr7PIYeo8/s320/Snap15-727667.jpg" border="0" /></a></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-size:100%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;">Then you will see the result.<br />The very power full point about Reporting service is that you can export data to different sources like pdf, Excel, Web services and etc.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-size:100%;" ></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:85%;"><span style="font-size:100%;">Please see the clip to get some more information. Also you will learn how to create Chart reports</span>.</span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjTpz-_Bvz6EISeO9NO86uFoA8S61xPDRE4v4IIAwFx7KVAzNpq2a74wNgMDvRJMflqC25rQs6FyiVG4KHwmNKOHmvaFqdhUIbnnZHzDVxO3LSW8JCo4a9jl5vMpGPAuwKg7UviqdmQxI/s1600-h/Snap16-728060.jpg"><img id="BLOGGER_PHOTO_ID_5206454398883103266" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjTpz-_Bvz6EISeO9NO86uFoA8S61xPDRE4v4IIAwFx7KVAzNpq2a74wNgMDvRJMflqC25rQs6FyiVG4KHwmNKOHmvaFqdhUIbnnZHzDVxO3LSW8JCo4a9jl5vMpGPAuwKg7UviqdmQxI/s320/Snap16-728060.jpg" border="0" /></a></p></span></span></span></span></span></span></div></span></span></span></span><p align="center"><br /><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ReportingServices.html');" href="http://www.csharpcourses.com/2008/05/create-report-with-reporting-services.html">See the clip</a> </p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com8tag:blogger.com,1999:blog-7712731644405234924.post-10129925422782545102008-05-30T06:17:00.010+10:002008-05-31T19:32:05.941+10:00Using Ajax in Asp.Net<div align="center"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ajax.html')" href="http://www.csharpcourses.com/2008/05/using-ajax-in-aspnet.html">See the Clip</a><br /><br /></div><div align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/ajaxsample.zip">Download the Source Code</a><br /></div><div align="left"><br />Before learning programming with Ajax It is necessary to understand Ajax and when it is worth full to use.</div><br /><strong>What is Ajax?</strong><br />Ajax is a library to help you call methods of server side in client (browser) without refreshing the whole page but part of page. Let’s say you have list of countries as soon as user selects a country you need to show cities of that country in another dropdown. Imagine you have different elements in this page. What you need is just updating city dropdown. This is the best case to use Ajax since other part of page will stay in the page and users just feel that city dropdown is updated.<br /><br /><strong><em>Ajax Help you to call server methods in client side without updating the whole page.</em></strong><br /><div align="justify"><br /><strong>When using Ajax is worth full?</strong><br />After working with Ajax a lot of programmers decide to use this technology a lot however, this is obviously a big mistake. Ajax should be used when implementing a functionality is completely impossible with javascript or massive data should be loaded to client. Let me give you an example if you need change data of a datagrid based on a dropdownlist it is not worth to write this code with javascript. If you need to just hide a part of data like a panel based on a check box it is not worth full to write this code with ajax.</div><div align="justify"><br /><strong><em>There is a trade-off between using Ajax and JavaScript. Never use Ajax when you are able to implement the same functionality with JavaScript as long as you are not forced to load massive data to client.</em></strong> </div><div align="justify"><br /><strong>How to create Ajax application?</strong><br />If you are using visual studio 2005 you may need to download ajax library. If you are using visual studio 2008 you have ajax library. After installing ajax you can create Asp.net Ajax-Enabled Web site from file new Web site. If you take a look to this project you will understand that there are some codes being added in web.config to enable ajax also at least for default page you will see a tag which is ScriptManager.<br /><br /><strong>Ajax Elements:<br /></strong>In each page that you need to use ajax technology you defiantly need a ScriptManger control which has no user interface but it mostly prepare ajax technology for that page. This control will add some library to browser and some javascript. <strong><em>It is important to put this control as the first control in html view in your page</em></strong>. Then you can use an update panel to place controls that are going to be updated between postback. For example let’s say we have a page with different content but a grid should be updated without posting back the whole page so we put that grid inside the Update Panel. If your task is time consuming you can use updateProgress control to show a picture identifying you are loading data. In this post I am going to talk about UpdatePanel. I will examine other controls in next posts. </div><div align="justify"><br /><strong>A sample code:</strong><br />In this sample I used the same product table was created for other samples of website which is a simple product table I need to show information of this table in a Gridview based on price. So when 200 is defined as price we need to show all products that are less than 200. Take a look to this picture. Then <a href="http://www.csharpcourses.com-a.googlepages.com/ajaxsample.zip">download the code </a>and also <a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/ajax.html')" href="http://www.csharpcourses.com/2008/05/using-ajax-in-aspnet.html">see the clip</a>.</div><div align="justify"></div><div align="justify"></div><div align="justify"></div><div align="justify"></div><br /><br /><img id="BLOGGER_PHOTO_ID_5205897835546050882" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha7yTHUYp4sVOdxpbj4OFloniSxQTuRt8i6hnvLEh90VPjcn6CPFAE9krRO21Fuv2haE9lLe4msD3ANwBJibb94Lw871Dca2asw_XW2MDXtxZ_LMvWpZfAJW-227lyeXuSmN8z48vcykk/s400/Snap1.jpg" border="0" />Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com1tag:blogger.com,1999:blog-7712731644405234924.post-59974053258875524352008-05-25T18:20:00.008+10:002008-05-30T06:16:30.175+10:00.Net Remoting Activator Sample<div align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/activator.zip">download the Samaple Code</a></div><div align="center"></div><div align="center"><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/DelegateActivator.html');" href="http://www.csharpcourses.com/2008/05/net-remoting-activator-sample.html">see the clip</a></div>In the previous lesson of Remoting I talked about remoting basics I examined a code sample. If you take a look to that post some people get back to me with the question how we can hide service from client process well this lesson is talk about how to hide Service from Client. First take a look to what we discussed in last lesson.<br /><div align="justify"></div><img id="BLOGGER_PHOTO_ID_5204229184916980002" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDmHGCy0k_j2WW56iEEYyNVPRO3oWcm8m3IvvVq1R4p9XnxjTtLsHfaED96wie80bA49eaCDaBaA2N5DY5vI7yhrVcfNsnRVTTn4iiAQAGm3gwj1TIVqj5mqoOKWfIf9u10wAFhGYtOeE/s400/Snap1.jpg" border="0" /><br /><p align="justify">As you see in above diagram client application is talking to server application to create an object which will be created in server. This object metadata (definition) is inside service app. What client needs to talk to server application is a proxy object. This proxy object will be created based on one of the classes in service app. For example if you have a class called Test with one method called Dosth. The proxy object in client will be a class called Test with one method called Dosth. When this method is called proxy object path this call to the serve so in the server the real object will be created then the method in serve is called. So Server definitely needs the service app to understand the Type “Test”. The Issue here is that in reality in most of the projects we do not like to give client the service application because a clever client may open this library and then could be a threat to our business rule or security. But how client can create proxy object if no Type is available in client process?<br /><br />See the movie please I explained more about this issue.<br /><br />There are two ways to solve this issue:</p><ol><li><div align="justify">You could create the same service app and change all code in new service app in a way that all methods even constructors throw an exception (I do not recommend this way since it is time consuming and there is no standardization. )</div></li><br /><li><div align="justify">Using interface between client and server is another approach. It means that each class in service app inherits from an interface it means that we need extra application that has just interfaces. Client has this library from where it can find metadata to create the proxy object. Meanwhile, client is not able to see the service implementation. We are done, However, there is a big issue here: if we just give client an interface then the proxy object will be like interface how we are going to create an object from interface? Well we do not create proxy object. We use Activator class to create an object from server application but map that to the interface take a look to this picture<br /><img id="BLOGGER_PHOTO_ID_5204229884996649266" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8KTMtw2z78uKn4nLOBZeKNbojjbtnmjmYVXzqMqNcNGDrB_aFaIWmaNmEBM4B3U6r3YzFtbHvKadaj8rgg1Cji9lfVrQmrk_w1F0KIlbf_WyK6LxTuLH64_CZowC5BlWJ_bC7ChpZxRg/s400/Snap2.jpg" border="0" /></div></li></ol><p align="justify">In above diagram as you see client just access to IService app that has just interface and interface does not have any implementation. And server has both of them. Server exposes Test object. Remember Test object is a type of ITest as well (because of inheritance) and client receive The test object but the way client look to Test object is ITest then when client call ITest methods the Test methods are called.</p><p align="justify">How to write activator code?<br />The coding that we had in previous example in client slightly changes take a look at this line of code. Let’s say I have a Hello class and IHello interface then the code in client is like this:</p><p align="left">IHello h = (IHello)Activator.GetObject (typeof(IHello),"<a href="http://localhost:4000/Myuri">http://localhost:4000/Myuri</a>");</p><p align="left">Activator object create an object in server as you see and then map that type to interface. Please see the code and also the clip. </p><p align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/activator.zip">download the Samaple Code</a></p><p align="center"><br /><a onclick="window.open('http://www.csharpcourses.com-a.googlepages.com/DelegateActivator.html');" href="http://www.csharpcourses.com/2008/05/net-remoting-activator-sample.html">see the clip</a> </p>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com8tag:blogger.com,1999:blog-7712731644405234924.post-17772851001295159022008-05-25T01:10:00.007+10:002008-05-25T02:06:08.028+10:00Multi tier Architecture utilities (NLOG)see these Related topics:<br /><ol><li><a href="http://www.csharpcourses.com/2008/05/multi-tier-programming-part1.html">Multi tier basics </a></li><li><a href="http://www.csharpcourses.com/2008/05/best-practice-for-multi-tier.html">A best practice for multi tier architecture </a></li><li><a href="http://www.csharpcourses.com/2008/05/multi-tier-sample-code-best-practice.html">A sample code based on best practice </a></li><li><a href="http://www.csharpcourses.com/2008/05/multi-tier-architecture-utilities-nlog.html">Examine utilities to speed up Multi tier programming- NLog</a></li></ol><p align="center"><a href="http://www.csharpcourses.com-a.googlepages.com/MultiTierSamplev2.zip">Please download the second version of Multi tier code</a></p><p align="justify">In previous lessons I talked about basic concepts of Multi tier and a best practice Architecture. Also I examine a sample code about that Architecture in this lesson I am going to review ”NLOG” one of the best tools that with no doubt you better use in that architecture to Log both errors and interaction with application.<br />What is NLOG?<br />NLOG is a free tool could be used to log into different resources like file, event viewer, database, Memory, Console, MSMQ, Mail and Web Service and etc. Meanwhile it can be configured to different level of log. Moreover, it can be switched off or on. Also you can have different source of log. Above of all it is open source application. Should you need any changes you will be able to make it.<br />How NLOG works?NLog gives you a class library to call its services. Also it has a configuration file called NLog.config where you set which log sources you need for instance file or database. Also you can configure the source for example for a file you probably configures the file name. You can have multiple sources. Take look at this sample:</p><img id="BLOGGER_PHOTO_ID_5203971143281836290" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgweWjz2-SGEAieIgmNmhNQL8rOcoTi-tEauXuA0ykYjcIu3JpSEhfos4cpWXklW3jjjmsYG3664eRZq0LST5CVk5LFM2N4DlimXZKnlSc2iPPIPknkoe8TH2mz5XXDh70HQJJiSH1JGrE/s400/Snap1.jpg" border="0" /><br /><div align="justify">this configuration file will be in UI application then other layers in Multi tier architecture do not need extra Nlog.config file all of them will use this configuration file. If you look at the logDirecotry in above code you will see that actually nlog will create a folder called Logs inside application folder and it will log data for each day. I just showed you logging in files. Log in other data sources like database has its own configuration variables.<br />It you look at the rules tag you will find two logger tags where you define each one of these logger<br />1- which class will represents them (“name”)<br />2- what is the minimum level of log also you can disable log by setting this value to debug for a release version of application (“minLevel”)<br />3- Which target this logger is using to log information</div><br /><div align="justify">In a multi tier application we always put our logger in Common Layer because we need this library in other layers. Also I highly recommend you to write a rapper class to simplify using NLog. <a href="http://www.csharpcourses.com-a.googlepages.com/MultiTierSamplev2.zip">Take a look at the DataLogger code</a>: </div><br /><br /><img id="BLOGGER_PHOTO_ID_5203971748872225042" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGPTRwHrAMI8RdEYbmebiVrcLXTMMwCgChjfen0hy2LvySRJRs4RNAuCsfGRYVqXCiL0R2JWYSsfHEctwipHqol4HQf5pen2iti-D2hWc0Y8N4khNyh8NAqg2kiJamtXI0HGHwZpJL9EQ/s400/Snap2.jpg" border="0" /><br /><div align="justify">In above code simply two methods are written Info and Warn to log information. If you look at the parameters you see multiple parameters. To save these parameters an xml structure is being used.<br />Please see the next version of multi tier code with logging<br />I remind you that I used very simple logging here you may change it and adapt it to your requirements. So this is not a best practice however, it is a good practice using Nlog in your projects. Nlog is really a lot more than I show you here. If you need any extra information or you think it is worth to have more detail information about NLOG let me know and raise some comments here. Do not underestimate this fabulous tool. I believe it needs at least 20 posts to show its capability!<br />In next lesson I am going to talk about my favourite tool Code Smith to generate code. Please download the next version of the code. </div><div align="center"><br /><a href="http://www.csharpcourses.com-a.googlepages.com/MultiTierSamplev2.zip">Please download the second version of Multi tier code</a></div>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com4tag:blogger.com,1999:blog-7712731644405234924.post-35454938982078482562008-05-22T06:22:00.004+10:002008-05-22T06:36:55.742+10:00sending configurable email in Asp.net (Best practice)<span style="font-family:'Georgia','serif';"><span style="font-size:100%;">Sending email is very common in Asp.net application. In most of asp.net applications I was asked to send email to client or admin etc. Meanwhile, almost always I was asked to change content of email many times. Like change a sentence, put space between sentences. Sometimes to create email the way client needs I had to change email content 10 times. Finally I come up with the idea that I need to make this process configurable and allow clients change the content themselves easily. Another issue is that since email is dependent to other factors like mail server sometimes your application may not be successful to send email so you need detect unsuccessful emails and send email in later steps. This Post will talk about best practice to send email to client.</span></span> <a href="http://www.csharpcourses.com-a.googlepages.com/sendingEmail.zip">please download the Code</a><br /><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">Understanding the issue:</span></span></b></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">We are going to send email to users. We need these functionalities:</span></span><br /></p><p class="MsoListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Georgia','serif'; mso-fareast-font-family: Georgiafont-family:Georgia;" ><span style="mso-list: Ignore"><span style="font-size:100%;">1-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">The Email content should be configurable</span></span></p><p class="MsoListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Georgia','serif'; mso-fareast-font-family: Georgiafont-family:Georgia;" ><span style="mso-list: Ignore"><span style="font-size:100%;">2-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">We may need to have a link in our email to somewhere in our site or in other sites</span></span></p><p class="MsoListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Georgia','serif'; mso-fareast-font-family: Georgiafont-family:Georgia;" ><span style="mso-list: Ignore"><span style="font-size:100%;">3-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="font-family:'Georgia','serif';">If sending email is not successful we need to log that email in database to be able to send email in future</span></p><div align="justify"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">You can send email in .net using System.Web.Mail.SmtpMail which is obsolete. Also you can use System.Net.Mail.SmtpClient I highly recommend the second one also try to use System.Net.MailMessage which is new class in .Net 2.0 unless you are using .net 1.1 By using SmtpClint class you can configure your smtp server information in web.config take a look at this code:<br /></div></span></span><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;"></span></span></b><img id="BLOGGER_PHOTO_ID_5202930306833379170" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidQ8Og9qkrwC9Y-53i0BwiI9XkgRIXLCgBikjmOvxfiDARWxBT0SRBtjqndUVsbWQEqlcNrkDkrjuGwdlslsTdXwbB1lTOTcSZ6g1b6Pv98W_QHI6JmbURr7Q68u8imtJBHHHhr-_aFss/s320/Snap1.jpg" border="0" /><br /><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">Quick look to class diagram:</span></span></b><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-family:'Georgia','serif';" ><span style="font-size:100%;"> </span></span><span style="font-family:'Georgia','serif';"></span></div><img id="BLOGGER_PHOTO_ID_5202930311128346482" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPxpFwlDuwUNmT2S6bQgZRX3G0pz7tpgNa2O8Ea-ClkQ1Di44JJbyk_-XkVbBA8NCFGP2rGK6BK3jk5Z07I7HzBgvX3h8FlARy8iGPe3B5CbUD-PG83hp9ccc6QFK4RQWGdInwpMJFyO8/s320/Snap2.jpg" border="0" /><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">I need to remind you that I did not use multi tier architecture here. I highly recommend that Accessing to database should be done through DataAccessLayer you can find more information about DataAccessLayer and multi tier programming in </span><a href="http://www.csharpcourses.com/2008/05/best-practice-for-multi-tier.html"><span style="font-size:100%;color:#800080;">my blog</span></a><span style="font-size:100%;">. </span></span></p><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">EmailHelper, EmailLog, EmailLogProvider, DataAccessHelper:</span></span></b></p><br /><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">UI will call EmailHelper class methods to send email in our case we have just one type of email if I had 10 different emails (of course with different content) I would have 10 methods to send Emails. All of those 10 methods would use SendEmail method (a private method) to send email. Also in this class there is another method called LogException used to Log the exception in database. Meanwhile, the email information is being saved so we can send email in later step to client. In this method an object of email log is being created then it is passed to EmailLogProvider Insert method to insert into database. DataAccessHelper is a utility class that you may use to add parameter to a command and to run a storedprocedures. In our example it is being used by EmailLogProvider class.</span></span></div><br /><div class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:'Georgia','serif';"></span><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">EmailReader, EmailLinkLoader:</span></span></b></div><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">When a method of EmailHelper is being called to send an email first a MailMessage object is created afterwards, it is passed to EmailReader class to prepare the body and other information. In this method we load information form an Xml file. So it is highly maintainable because as long as client gets back to us to change content of email we can apply those changes in this xml file not to our code. Take a look of this xml file.</span></span></p><img id="BLOGGER_PHOTO_ID_5202930315423313794" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic913gqzSTCCRlO4LTEVV5u8VmF9hGISMknTNBA4hGEEeKMVL6JIZUxQvwt2_tal-XBekrDDwpWI0PBLeGg3N12LLfWCiXc5EVPaeH7dUZePXpt5tk89sEidlyL9EeZYx5HJvmmaNkj2o/s320/Snap3.jpg" border="0" /><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-family:'Georgia','serif';" ></span><span style="font-family:'Georgia','serif';"></span></p><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">As you see we even have "from emai"l and "from email display name" also as many as required bcc email can be configured. A very nice trick in this code is that if you look closer to the xml file you will find $firstName$ . This is a key for our code and we will replace this value in EmailLoader.LoadRegistration .So the email can have dynamic information for example another good example is that you may want to send username and password to a user but this information may vary from one user to another user so we use other keys and we replace this information in our code exactly the same way for $firstName$. In most of the sites that I worked I had more than one email also many of them had some special links like Terms and Condition link that should be placed into email. A good practice always suggests that never put a link hard coded as long as you have more than one email content connecting to the same link. So imagine you have 5 email and all of them somewhere in their content have a link to Terms and condition. You better make this link configurable because when this link changes you need change just one configuration rather than looking for this link in all emails. So EmailLinkLoader actually load another xml file and find the link address then cache this information. So next time it does not need to look up link again. This link information is passed to EmailReader to be applied to body content.</span></span></p><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;"></span></span></p><img id="BLOGGER_PHOTO_ID_5202930315423313810" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh3YslltbGE7oAvKcdPe7Goj6bsLdsCX3jj33TrNfjL8yMAQonkywoW9AuVROXCrS927H811bGWKlB0qf2stp26a0OyNH_SkO_etrJKquh98lvXGKnnIGDTfcA6rjf-AnFXjT_kl-Dbzs/s320/Snap4.jpg" border="0" /><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="mso-fareast-language: EN-AU; mso-no-proof: yesfont-family:'Georgia','serif';" ></span><span style="font-family:'Georgia','serif';"></span></p><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size:100%;"><b style="mso-bidi-font-weight: normal"><span style="font-family:'Georgia','serif';">Important</span></b><span style="font-family:'Georgia','serif';"> <b style="mso-bidi-font-weight: normal">(how to run the code)</b></span></span></p><br /><p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt; TEXT-ALIGN: justify"><span style="font-family:'Georgia','serif';"><span style="font-size:100%;">Open Visual studio and form file menu select open web site and form file system select the project folder. Afterwards you can run the project. You need to apply smtpserver address. A good test is without applying smtpserver if you run application then application ask your first Name and your email address. Afterwards since sending email is not successful the email information is saved into database. And it shows you unsuccessful message. In later steps we can use EmailLogProvider class and load all EmailLog objects so we can retry and resend email.</span></span></p><br /><a href="http://www.csharpcourses.com-a.googlepages.com/sendingEmail.zip">please download the Code</a>Emad Yazdanhttp://www.blogger.com/profile/09070609059622439370noreply@blogger.com0