<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5806124225165493233</id><updated>2012-02-16T19:44:31.019-08:00</updated><category term='winform'/><category term='c#'/><category term='backgroundworker'/><category term='AOP'/><category term='dependency injection'/><category term='console application'/><category term='ajax asp.net 2.0 vs2005'/><category term='cursor'/><category term='windows forms'/><category term='c# .net'/><category term='lambda expressions'/><category term='refreshing automatically'/><category term='static delegates'/><category term='multithreading'/><category term='asp.net'/><category term='instance delegates'/><category term='Aspect Oriented Programming'/><category term='windsor castle'/><category term='progress bar'/><category term='delegates'/><category term='response.appendhandler'/><title type='text'>asp.net</title><subtitle type='html'>blogg about c#.net and sql server</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7071132318649997186</id><published>2009-06-15T05:36:00.001-07:00</published><updated>2009-06-15T05:41:25.100-07:00</updated><title type='text'></title><content type='html'>&lt;a href="http://3.bp.blogspot.com/_IfN9TUWZV7U/SjZBRPB2nLI/AAAAAAAAAB8/14xvjzgyy80/s1600-h/TFSPhysicalArchitecture.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5347533371896929458" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 282px" alt="" src="http://3.bp.blogspot.com/_IfN9TUWZV7U/SjZBRPB2nLI/AAAAAAAAAB8/14xvjzgyy80/s400/TFSPhysicalArchitecture.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_IfN9TUWZV7U/SjZBLT4zLQI/AAAAAAAAAB0/OTtZoN189NU/s1600-h/TFSArchitecture.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5347533270121917698" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; WIDTH: 400px; CURSOR: hand; HEIGHT: 217px" alt="" src="http://1.bp.blogspot.com/_IfN9TUWZV7U/SjZBLT4zLQI/AAAAAAAAAB0/OTtZoN189NU/s400/TFSArchitecture.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TEAM FOUNDATION SERVER OVERVIEW&lt;br /&gt;&lt;br /&gt;Visual Studio Team System (VSTS) integrates in one place a set of tools that enable a team to collaborate and coordinate their efforts on building and completing an application.&lt;br /&gt;&lt;br /&gt;A team project is stored on Team Foundation Server (TFS) and has a name everyone on the team can easily identify.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TFS Architecture&lt;br /&gt;&lt;br /&gt;Logical Architecture&lt;br /&gt;TFS is a structured as a multi-layered application, consisting of a client layer, a business or application layer and data layer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Data is stored in a MS-SQL server 2005 database. TFS creates a number of databases and tables for maintaining users, work items, source control and other resources.&lt;br /&gt;&lt;br /&gt;The Application layer consists in a set of services which are available over the network. Most of these services are configured as web services which makes them accessible over the Internet.&lt;br /&gt;&lt;br /&gt;Physical Architecture&lt;br /&gt;&lt;br /&gt;It is recommended that for any installation, the data tier and the application tier are on different servers to meet the scalability and reliability requirements. Nevertheless, it is possible to have them in the same tier for installations which do not demand high scalability.&lt;br /&gt;&lt;br /&gt;It is recommended to have a separate build server since the build activity is very highly CPU intensive. Keeping the main TFS and build server on same machine with frequent builds may undermine the performance of TFS adversely.&lt;br /&gt;&lt;br /&gt;TFS supports the development of projects for teams that are working locally as well as for teams which are geographically scattered and connected remotely. To do that it uses proxies.&lt;br /&gt;&lt;br /&gt;The following figure shows the standard physical architecture of TFS.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Services Offered by TFS&lt;br /&gt;&lt;br /&gt;The main goal of TFS is to improve collaboration between multiple users in a development team. To do that it provides the following services:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Source Code Control (SCC)&lt;br /&gt;&lt;br /&gt;SCC is the source control system of TFS. It includes operations such as versioning, Branching, Merging, Shelving, Un-shelving, etc. The source control is maintained in a SQL Server 2005 database. It allows multiple check-outs, placing locks on files, check-in policies which makes team members to execute certain actions when they are checking in source code.&lt;br /&gt;&lt;br /&gt;Typically Team Foundation version control is used for source files but it is possible to add non-source files such as important project documentation.&lt;br /&gt;&lt;br /&gt;Project Portal&lt;br /&gt;&lt;br /&gt;Each team project has an associated project portal that is a Windows SharePoint Web site. Team members can use the project portal to store documents, find reports, and use other collaborative features.&lt;br /&gt;&lt;br /&gt;Team Explorer&lt;br /&gt;All team members work with team projects by using Team Explorer in the Visual Studio IDE. Team Explorer connects to one Team Foundation Server and displays team projects from that server. By using Team Explorer, every team member can find and update work items, view reports, manage documents, and work with product builds.&lt;br /&gt;&lt;br /&gt;Alerts&lt;br /&gt;Team Foundation provides alerts that are sent to you through e-mail when something changes on the team project. Alerts can be sent when the status of a work item changes, a check-in occurs, a build is completed, or when a build status changes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Work Item Tracking&lt;br /&gt;&lt;br /&gt;Team Foundation uses the concept of a work item to track fundamental pieces of work on a team project. Various types of work items are available and are based on the type of work that they represent.&lt;br /&gt;Work item queries are used to find work items that match a specific set of criteria. Queries are useful to find the current status on work items.&lt;br /&gt;All work items have a running history that logs all activity. Whenever a work item changes, whether the item's status changes to closed or notes are updated with new information, all the changes are logged so that anyone can review the complete history of activity on a work item at any time.&lt;br /&gt;&lt;br /&gt;Microsoft Project and Excel Integration&lt;br /&gt;&lt;br /&gt;Work items are stored in a database on the Team Foundation server; however, copies of work items can be imported and tracked in Microsoft Project or Microsoft Excel. For example, task work items can be imported into Microsoft Project and organized to load balance work for team members. Also, bug work items can be imported into Microsoft Excel to create a list of top priority bugs that must be fixed.&lt;br /&gt;&lt;br /&gt;Building Automation&lt;br /&gt;&lt;br /&gt;Each developer compiles the application in its workspace on the local machine. After compilation, the code is checked in the source code control. The checked in code has to be built to ensure its interoperability with code created at other time, maybe, by some other developers. This build process should be carried out periodically to ensure integrity of all the checked in code. TFS allows creation of build at pre-determined time using a component called Team Build. Team build schedules the build script created using MS-Build to be executed at the predetermined time.&lt;br /&gt;&lt;br /&gt;Reporting&lt;br /&gt;&lt;br /&gt;Reports are stored in a database on the Team Foundation server, and they track status and trend information over time on a team project. The data for the reports is stored in a data warehouse and collected from the operational databases on Team Foundation server. Types of information that can be tracked in reports are work item changes, check-ins, status on product builds, and test results. Also, cross-project reports can compare historical data for multiple projects.&lt;br /&gt;&lt;br /&gt;Roles&lt;br /&gt;Roles are assumed by one or more team members on a team project, and each role represents one or more disciplines that are required to successfully complete the team project.&lt;br /&gt;Roles do not represent a one-to-one relationship with job titles or disciplines.&lt;br /&gt;&lt;br /&gt;The Help documentation organizes content into three general roles: Administrators, Project Leads, and Project Members. These general roles are used by the Help documentation to help you find the tasks and information that most likely apply to you when you work on a team project.&lt;br /&gt;&lt;br /&gt;Security Groups&lt;br /&gt;&lt;br /&gt;Team Foundation security groups enforce permissions available for each team member. When a new team project starts, the administrator maps process roles for that team project to specific security groups and permissions. Additionally, the process template defines a default set of security groups.&lt;br /&gt;&lt;br /&gt;Tool Integration&lt;br /&gt;&lt;br /&gt;Team Foundation tools integrate with each other to automate many tasks that typically do not occur between tools. For example, when you check in source code to fix a bug, you can automatically resolve the work item that describes the bug.&lt;br /&gt;Many Team Foundation tools are integrated with the Visual Studio. Team Explorer is the main window to work with team projects. Additional windows are available from Team Explorer such as Source Control Explorer, and the Build Explorer.&lt;br /&gt;&lt;br /&gt;Team Foundation can also be extended to integrate additional tools that are created by third-party organizations.&lt;br /&gt;&lt;br /&gt;Team Foundation can be used with older Visual Studio projects.&lt;br /&gt;&lt;br /&gt;Customisation&lt;br /&gt;Team Foundation supports customization of work items, work item instances, reports, security, project portal, documents and templates, source control settings, and process guidance content.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7071132318649997186?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7071132318649997186/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7071132318649997186' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7071132318649997186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7071132318649997186'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/team-foundation-server-overview-visual.html' title=''/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_IfN9TUWZV7U/SjZBRPB2nLI/AAAAAAAAAB8/14xvjzgyy80/s72-c/TFSPhysicalArchitecture.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1023543904072722938</id><published>2009-06-11T07:30:00.004-07:00</published><updated>2009-06-11T07:31:20.947-07:00</updated><title type='text'>using the Logging Access Application Block (DAAB) in Enterprise Library</title><content type='html'>We can log info to: event log, email,DB,msg queue, text file, WMI event or to a custom location.&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;using Microsoft.Practices.EnterpriseLibrary.Common;&lt;br /&gt;using Microsoft.Practices.EnterpriseLibrary.Logging;&lt;br /&gt;using Microsoft.Practices.ObjectBuilder;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;LogEntry log = new LogEntry();&lt;br /&gt;log.EventId=111;&lt;br /&gt;log.Message = "Sample Log Message";&lt;br /&gt;log.Categories.Add("Trace");&lt;br /&gt;Logger.Write(log);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1023543904072722938?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1023543904072722938/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1023543904072722938' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1023543904072722938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1023543904072722938'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/using-logging-access-application-block.html' title='using the Logging Access Application Block (DAAB) in Enterprise Library'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-5027710143552671620</id><published>2009-06-11T07:30:00.003-07:00</published><updated>2009-06-11T07:30:53.274-07:00</updated><title type='text'>using the Data Access Application Block (DAAB) in Enterprise Library</title><content type='html'>a) selecting all the columns &lt;br /&gt;Database db = DatabaseFactory.CreateDataBase();&lt;br /&gt;string sqlQuery = "SELECT * FROM EMPLOYEES";&lt;br /&gt;IDataReader reader = db.ExecuteReader(CommandType.Text, sqlQuery);&lt;br /&gt;&lt;br /&gt;b) Passing a parameter&lt;br /&gt;Database db = DatabaseFactory.CreateDataBase();&lt;br /&gt;string sqlQuery = "SELECT * FROM EMPLOYEES WHERE CategoryId =@CategoryId";&lt;br /&gt;DBCommandWrapper command = db.GetSqlCommandWrapper(sqlQuery);&lt;br /&gt;command.AddInParameter("@CategoryId",DbType.Int32.categoryId);&lt;br /&gt;IDataReader reader = db.ExecuteReader(CommandType.Text, sqlQuery);&lt;br /&gt;&lt;br /&gt;c) Using Stored procedures&lt;br /&gt;Database db = DatabaseFactory.CreateDataBase();&lt;br /&gt;//specify params for the stored procedure&lt;br /&gt;IDataReader reader = db.ExecuteReader("sprocname", paramvalue1, paramValue2,....);&lt;br /&gt;&lt;br /&gt;ExecuteReader returns a DataReader (forward only cursor)&lt;br /&gt;ExecuteDataSet returns a DataSet &lt;br /&gt;ExecuteScalar returns a scalar&lt;br /&gt;ExecuteNonQuery doesn't return a value&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-5027710143552671620?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/5027710143552671620/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=5027710143552671620' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/5027710143552671620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/5027710143552671620'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/using-data-access-application-block.html' title='using the Data Access Application Block (DAAB) in Enterprise Library'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8124774143538164998</id><published>2009-06-11T07:30:00.001-07:00</published><updated>2009-06-11T07:30:23.301-07:00</updated><title type='text'>JSON (javaScript Object Notation) strings</title><content type='html'>It is another standard used to format data.&lt;br /&gt;For instance here we have an XML notation:&lt;br /&gt;&lt;br /&gt;&amp;ltskills&amp;gt&lt;br /&gt;&amp;ltweb&amp;gt&lt;br /&gt;&amp;ltskill&amp;gt&lt;br /&gt;&amp;ltname&amp;gthtml&amp;lt/name&amp;gt&lt;br /&gt;&amp;ltyears&amp;gt5&amp;lt/years&amp;gt&lt;br /&gt;&amp;lt/skill&amp;gt&lt;br /&gt;&amp;ltskill&amp;gt&lt;br /&gt;&amp;ltname&amp;gtcss&amp;lt/name&amp;gt&lt;br /&gt;&amp;ltyears&amp;gt4&amp;lt/years&amp;gt&lt;br /&gt;&amp;lt/skill&amp;gt&lt;br /&gt;&amp;lt/web&amp;gt&lt;br /&gt;&amp;lt/skills&amp;gt&lt;br /&gt;&lt;br /&gt;This would be the equivalent in JSON:&lt;br /&gt;&lt;br /&gt;{"skills":&lt;br /&gt; {"web":&lt;br /&gt;  [&lt;br /&gt;   {"name":"html","years":"5"}&lt;br /&gt;   {"name":"css" ,"years":"4"}&lt;br /&gt;  ]&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Normally we will have a program that will build the JSON strings and another that will parse them.&lt;br /&gt;.NET provides a set of classes that allow to build and parse JSON strings in the same way that we have also classes to do the same for XML files. &lt;br /&gt;One of them is Jayrock.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8124774143538164998?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8124774143538164998/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8124774143538164998' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8124774143538164998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8124774143538164998'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/json-javascript-object-notation-strings.html' title='JSON (javaScript Object Notation) strings'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-4998248960683691614</id><published>2009-06-11T07:15:00.000-07:00</published><updated>2009-06-11T07:16:14.562-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='lambda expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><title type='text'>Lambda expressions</title><content type='html'>c# 1.0 and 1.1&lt;br /&gt;&lt;br /&gt;public MyForm()&lt;br /&gt;{&lt;br /&gt;   listBox   = new ListBox(...);&lt;br /&gt;   textBox   = new TextBox(...);&lt;br /&gt;   addButton = new Button(...);&lt;br /&gt;   addButton.Click += new EventHandler(AddClick);&lt;br /&gt;}&lt;br /&gt;void AddClick(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;   listBox.Items.Add(textBox.Text);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In c# 2.0&lt;br /&gt;&lt;br /&gt;public MyForm()&lt;br /&gt;{&lt;br /&gt;   listBox   = new ListBox(...);&lt;br /&gt;   textBox   = new TextBox(...);&lt;br /&gt;   addButton = new Button(...);&lt;br /&gt;   addButton.Click += delegate&lt;br /&gt;   {&lt;br /&gt;      listBox.Items.Add(textBox.Text);&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;you don't have to explicitly declare a new method to link it with an event. &lt;br /&gt;Another alternative is to use anonymous methods.&lt;br /&gt;&lt;br /&gt;(int x) =&amp;gt x + 1          // explicitly typed parameter (i.e parameter specified)&lt;br /&gt;(y,z) =&amp;gt return y * z;    // implicitly typed parameter (i.e. parameter type inferred from the context)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-4998248960683691614?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/4998248960683691614/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=4998248960683691614' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4998248960683691614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4998248960683691614'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/lambda-expressions.html' title='Lambda expressions'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8573445850999501087</id><published>2009-06-11T07:13:00.001-07:00</published><updated>2009-06-11T07:15:26.596-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Aspect Oriented Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='AOP'/><title type='text'>Aspect Oriented Programming (AOP) with Windsor Castle</title><content type='html'>Imagine that we have a class called Employee. This class might have a method called Save(), which saves a new employee record into the database.This method will have calls to the database and imagine as well that we log all new employees somewhere. &lt;br /&gt;&lt;br /&gt;In terms of Aspect Oriented Programming in this method we have the Main Concern code (the code that saves the record employee into the database) and the Cross Cutting code, which is the code that is inside our method but that actually is not part of the main purpose of our code. In this case is all the code that performs the logging, but the same problem would exist in case of transactions, security or when invoking other functionality such could be a method in our application that performs an action (such as printing).&lt;br /&gt;&lt;br /&gt;This mix of Main concern and Cross cutting concern results normally in a tangled code. Aspect Oriented programming pretends to give solutions to untangle this code.&lt;br /&gt;&lt;br /&gt;Normally some languages provide solutions at compilation level, but unfortunately the .NET compiler is not AOP compliant. A solution could be to implement our code using attributes, but this also has its limitations. Another alternative is using Windsor castle.&lt;br /&gt;&lt;br /&gt;Castle provides an interface called IInterceptor:&lt;br /&gt;&lt;br /&gt;public interface IInterceptor&lt;br /&gt;{&lt;br /&gt; void Intercept(IInvocation invocation);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then in our instance the class that performs the logging should be implement this interface:&lt;br /&gt;&lt;br /&gt;public class Logger:IInterceptor&lt;br /&gt;{&lt;br /&gt; public void Intercept(IInvocation innvocation)&lt;br /&gt; {&lt;br /&gt;  Logger.Write("Method:" + innvocation.Method.Name + " user:" + thread.CurrentPrincipal.identity.Name);&lt;br /&gt;  Innvocation.Proceed();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then by providing a configuration file we would instruct the program to invoke the Logger everytime we Save the employee in our database without needing to specify anything in the code. So everything is done behind the scenes.&lt;br /&gt;&lt;br /&gt;In our case the employee class that exposes the save method would look simply like this:&lt;br /&gt;&lt;br /&gt;public class Employee:IEmployee&lt;br /&gt;{&lt;br /&gt; public void save(Employee employee) { //inserts record into the DB and invokes Logger behind the scenes}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;So in our case we would have a config file that would look something like this:&lt;br /&gt;&lt;br /&gt;&amp;ltcomponent id="Logger" service="&amp;ltnamespace of Logger&amp;gt,&amp;ltassembly of Logger&amp;gt" type="&amp;ltnamespace of Logger&amp;gt,&amp;ltassembly of Logger&amp;gt" /&amp;gt&lt;br /&gt;&amp;ltcomponent id="Employee" service="&amp;ltnamespace of Employee&amp;gt,&amp;ltassembly of Employee&amp;gt" type="&amp;ltnamespace of Employee&amp;gt,&amp;ltassembly of Employee&amp;gt"&amp;gt&lt;br /&gt; &amp;ltinterceptors&amp;gt&lt;br /&gt;  &amp;ltinterceptor&amp;gt${Logger}&amp;lt/interceptor&amp;gt&lt;br /&gt; &amp;lt/interceptors&amp;gt&lt;br /&gt;&amp;lt/component&amp;gt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If instead of logging we would like to perform a transaction then we could do something like this:&lt;br /&gt;&lt;br /&gt;public class Transaction: IInterceptor&lt;br /&gt;{&lt;br /&gt; public void Intercept(IInvocation invocation)&lt;br /&gt; {&lt;br /&gt;  using (Transactionscope scope = new TransactionScope())&lt;br /&gt;  {&lt;br /&gt;   //do something&lt;br /&gt;   invocation.Proceed();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8573445850999501087?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8573445850999501087/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8573445850999501087' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8573445850999501087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8573445850999501087'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/aspect-oriented-programming-aop-with.html' title='Aspect Oriented Programming (AOP) with Windsor Castle'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-4588163857507833550</id><published>2009-06-11T07:13:00.000-07:00</published><updated>2010-10-24T03:06:42.691-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Aspect Oriented Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='AOP'/><category scheme='http://www.blogger.com/atom/ns#' term='windsor castle'/><title type='text'>Aspect Oriented Programming (AOP) with Windsor Castle</title><content type='html'>Imagine that we have a class called Employee. This class might have a method called Save(), which saves a new employee record into the database.This method will have calls to the database and imagine as well that we log all new employees somewhere.&lt;br /&gt;&lt;br /&gt;In terms of Aspect Oriented Programming in this method we have the Main Concern code (the code that saves the record employee into the database) and the Cross Cutting code, which is the code that is inside our method but that actually is not part of the main purpose of our code. In this case is all the code that performs the logging, but the same problem would exist in case of transactions, security or when invoking other functionality such could be a method in our application that performs an action (such as printing).&lt;br /&gt;&lt;br /&gt;This mix of Main concern and Cross cutting concern results normally in a tangled code. Aspect Oriented programming pretends to give solutions to untangle this code.&lt;br /&gt;&lt;br /&gt;Normally some languages provide solutions at compilation level, but unfortunately the .NET compiler is not AOP compliant. A solution could be to implement our code using attributes, but this also has its limitations. Another alternative is using Windsor castle.&lt;br /&gt;&lt;br /&gt;Castle provides an interface called IInterceptor:&lt;br /&gt;&lt;br /&gt;public interface IInterceptor&lt;br /&gt;{&lt;br /&gt; void Intercept(IInvocation invocation);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then in our instance the class that performs the logging should be implement this interface:&lt;br /&gt;&lt;br /&gt;public class Logger:IInterceptor&lt;br /&gt;{&lt;br /&gt; public void Intercept(IInvocation innvocation)&lt;br /&gt; {&lt;br /&gt;  Logger.Write("Method:" + innvocation.Method.Name + " user:" + thread.CurrentPrincipal.identity.Name);&lt;br /&gt;  Innvocation.Proceed();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then by providing a configuration file we would instruct the program to invoke the Logger everytime we Save the employee in our database without needing to specify anything in the code. So everything is done behind the scenes.&lt;br /&gt;&lt;br /&gt;In our case the employee class that exposes the save method would look simply like this:&lt;br /&gt;&lt;br /&gt;public class Employee:IEmployee&lt;br /&gt;{&lt;br /&gt; public void save(Employee employee) { //inserts record into the DB and invokes Logger behind the scenes}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;So in our case we would have a config file that would look something like this:&lt;br /&gt;&lt;br /&gt;&lt;component id="Logger" service=""&gt;,&lt;assembly&gt;" type="&lt;namespace&gt;,&lt;assembly&gt;" /&gt;&lt;br /&gt;&lt;component id="Employee" service=""&gt;,&lt;assembly&gt;" type="&lt;namespace&gt;,&lt;assembly&gt;"&gt;&lt;br /&gt; &lt;interceptors&gt;&lt;br /&gt;  &lt;interceptor&gt;${Logger}&lt;/interceptor&gt;&lt;br /&gt; &lt;/interceptors&gt;&lt;br /&gt;&lt;/component&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If instead of logging we would like to perform a transaction then we could do something like this:&lt;br /&gt;&lt;br /&gt;public class Transaction: IInterceptor&lt;br /&gt;{&lt;br /&gt; public void Intercept(IInvocation invocation)&lt;br /&gt; {&lt;br /&gt;  using (Transactionscope scope = new TransactionScope())&lt;br /&gt;  {&lt;br /&gt;   //do something&lt;br /&gt;   invocation.Proceed();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-4588163857507833550?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/4588163857507833550/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=4588163857507833550' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4588163857507833550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4588163857507833550'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/aspect-oriented-programming-aop-with_11.html' title='Aspect Oriented Programming (AOP) with Windsor Castle'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8235111127841057411</id><published>2009-06-11T06:22:00.000-07:00</published><updated>2009-06-11T07:13:09.135-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dependency injection'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='windsor castle'/><title type='text'>Dependency Injection with Windsor Castle</title><content type='html'>Situation: we have several classes(Class1, Class2, ClassN) that implement an interface (IClass). Suppose that this interface have a method:&lt;br /&gt;&lt;br /&gt;double GetQuote(string companyName); &lt;br /&gt;&lt;br /&gt;Windsor Castle allows to define wich implementation to use of this interface by just defining them in configuration files:&lt;br /&gt;&lt;br /&gt;WindsorContainer container = new WindsorContainer(new XmlIntercepter());&lt;br /&gt;IClass service = container.Resolve&amp;ltIClass&amp;gt("Class1");&lt;br /&gt;double price = service.GetQuote("Company");&lt;br /&gt;&lt;br /&gt;The configuration file would look somthing like this:&lt;br /&gt;&lt;br /&gt;&amp;lt?xml...&amp;gt&lt;br /&gt;&amp;ltconfiguration&amp;gt&lt;br /&gt;&amp;ltconfigSections&amp;gt&lt;br /&gt;&amp;ltsection name="Castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/&amp;gt&lt;br /&gt;&amp;lt/configSections&amp;gt&lt;br /&gt;&amp;ltcastle&amp;gt&lt;br /&gt;&amp;ltcomponents&amp;gt&lt;br /&gt;&amp;ltcomponent id="Class1" service="&amp;ltnamespace where the interface IClass is defined&amp;gt" type="namespace where Class1 is defined" /&amp;gt&lt;br /&gt;&amp;ltcomponent id="Class2" service="&amp;ltnamespace where the interface IClass is defined&amp;gt" type="namespace where Class2 is defined" /&amp;gt&lt;br /&gt;...&lt;br /&gt;&amp;ltcomponent id="ClassN" service="&amp;ltnamespace where the interface IClass is defined&amp;gt" type="namespace where ClassN is defined" /&amp;gt&lt;br /&gt;&lt;br /&gt;&amp;lt/components&amp;gt&lt;br /&gt;&amp;lt/castle&amp;gt&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;a) If we don't specify the implementation it takes the first one that finds in the config file. In this case would be Class1. &lt;br /&gt;IClass service = container.Resolve&amp;ltIClass&amp;gt();&lt;br /&gt;&lt;br /&gt;b) If we don' want to use the configuration file we still could do something like this:&lt;br /&gt;&lt;br /&gt;WindsorContainer container = new WindsorContainer(new XmlIntercepter());&lt;br /&gt;container.AddComponent("Class1",typeof("IClass"),typeof("Class1"));&lt;br /&gt;container.AddComponent("Class2",typeof("IClass"),typeof("Class2"));&lt;br /&gt;...&lt;br /&gt;container.AddComponent("ClassN",typeof("IClass"),typeof("ClassN"));&lt;br /&gt;IClass service = container.Resolve&amp;ltIClass&amp;gt("Class1");&lt;br /&gt;double price = service.GetQuote("Company");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8235111127841057411?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8235111127841057411/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8235111127841057411' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8235111127841057411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8235111127841057411'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2009/06/dependency-injection-with-windsor.html' title='Dependency Injection with Windsor Castle'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-2721896891997470036</id><published>2008-12-04T12:27:00.000-08:00</published><updated>2008-12-04T12:31:46.848-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ajax asp.net 2.0 vs2005'/><title type='text'>AJAX: installation and ajax enabling an existing website</title><content type='html'>These are the steps to follow to install ajax and to ajax enable an&lt;br /&gt;existing website:&lt;br /&gt;&lt;br /&gt;Installing AJAX&lt;br /&gt;&lt;br /&gt;1. Go to http://www.asp.net/ajax/downloads/ and download ASP.NET&lt;br /&gt;Extensions v1.0.&lt;br /&gt;2. Install Ajax Extensions.&lt;br /&gt;3. Go to www.codeplex.com\releases and download Ajax Toolkit. The&lt;br /&gt;toolkit has to be compatible with VS2005. I choose one from 2007&lt;br /&gt;(10301). You have 2  possibilities: downloading the version with code or&lt;br /&gt;the version with just the dlls. I downloaded the version with the code.&lt;br /&gt;this way you will be able to use  the examples built in the sample&lt;br /&gt;code.&lt;br /&gt;4. Extract the file in a sensible place. I did just in the same folder&lt;br /&gt;where Ajax extensions was installed:C:\Program Files\Microsoft ASP.NET.&lt;br /&gt;So I created a  folder inside this directory called Ajax toolkit and I&lt;br /&gt;extracted the content of the zip file.&lt;br /&gt;5. Go to C:\Program Files\Microsoft ASP.NET\Ajax Toolkit and open the&lt;br /&gt;solution. Inside you will fins a project called Template VSI. Build this&lt;br /&gt;project in  order to generate the .dll.&lt;br /&gt;6. Move binaries: go to C:\Program Files\Microsoft ASP.NET\Ajax&lt;br /&gt;Toolkit\SampleWebSite\Bin and copy the following binaries:&lt;br /&gt;AjaxControlToolKit.dll and  AjaxControlTollKit.pdb to C:\Program&lt;br /&gt;Files\Microsoft ASP.NET\Ajax Toolkit\Binaries&lt;br /&gt;7. Go to C:\Program Files\Microsoft ASP.NET\Ajax&lt;br /&gt;Toolkit\TemplateVSI\bin and click on AjaxControlExtender.vsi in order to&lt;br /&gt;install all Ajax toolkit extenders.&lt;br /&gt;8. Open VS2005. You see a tab with the Ajax extensions in it.&lt;br /&gt;9. Create a new tab on the tool box called Ajax toolkit. Browse to find&lt;br /&gt;the C:\Program Files\Microsoft ASP.NET\Ajax&lt;br /&gt;Toolkit\Binaries\AjaxControlToolKit.dll.  After that you will be able to&lt;br /&gt;see all the ajax toolkit control extensions on the toolbox.&lt;br /&gt;&lt;br /&gt;Ajaxcing an existing application:&lt;br /&gt;&lt;br /&gt;1. Backup the web.config file of the website that we want to convert&lt;br /&gt;into ajax.&lt;br /&gt;2. Create a new blank "ajax-enabled website" template.&lt;br /&gt;3. Open the web.config file for the new website and add the content of&lt;br /&gt;the web.config of the ajax-enabled website into the web.config of the&lt;br /&gt;website that we  want to enable. Put each section in the right place.&lt;br /&gt;4. Rebuild the website&lt;br /&gt;&lt;br /&gt;5. Add ONE and only ONE ScriptManager for each web page where we want&lt;br /&gt;to add ajax.&lt;br /&gt;6. Rebuild the website. If we get an error message saying that&lt;br /&gt;scriptmanger could not been recognized and that if we are missing a&lt;br /&gt;reference, then Add the  follwing reference "Syste.Web.Extensions" to&lt;br /&gt;the web site.&lt;br /&gt;7. Start adding the ajax controls that we want to insert. For instance&lt;br /&gt;try this calendar control:&lt;br /&gt;&lt;br /&gt;Calendar control:&lt;br /&gt;&lt;br /&gt;&amp;ltasp:TextBox ID="calendar1" runat="server"&amp;gt&amp;lt/asp:TextBox&amp;gt&lt;br /&gt;&amp;ltcc2:CalendarExtender ID="CalendarExtender1" runat="server"&lt;br /&gt;TargetControlID="calendar1" Format="dd MMM yyyy"&amp;gt&lt;br /&gt;&amp;lt/cc2:CalendarExtender&amp;gt&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-2721896891997470036?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/2721896891997470036/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=2721896891997470036' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2721896891997470036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2721896891997470036'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/12/ajax-installation-and-ajax-enabling.html' title='AJAX: installation and ajax enabling an existing website'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-2637736135497561177</id><published>2008-11-26T06:04:00.000-08:00</published><updated>2008-11-26T06:16:27.138-08:00</updated><title type='text'>Windows Forms: Application and User settings</title><content type='html'>Application settings can not be modified. If we want to store settings that are modifiable then need to be user's settings.&lt;br /&gt;Users settings are normally stored in the local machine in a directory that looks like this in a windows XP machine:&lt;br /&gt;&lt;em&gt;C:\Documents and Settings\mvc\Local Settings\Application Data\MyApp\MyAppAppli_Url_msha2jkulxful3zndimxtcs2sqtnuxse\1.0.0.0&lt;/em&gt;&lt;br /&gt;where MyApp is the name of my application and mvc is my network userId.&lt;br /&gt;&lt;br /&gt;To read a setting called numberOfUsers:&lt;br /&gt;Properties.Settings.Default.numberOfUsers&lt;br /&gt;To save all settings, just assign the values to all settings and then invoke save:&lt;br /&gt;  Properties.Settings.Default.SamplesOfThePastDays = Convert.ToInt32(textBoxDays.Text);&lt;br /&gt;...&lt;br /&gt;  &lt;strong&gt;Properties.Settings.Default.Save();&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-2637736135497561177?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/2637736135497561177/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=2637736135497561177' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2637736135497561177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2637736135497561177'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/11/windows-forms-application-and-user.html' title='Windows Forms: Application and User settings'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7864064490347625379</id><published>2008-11-26T05:50:00.000-08:00</published><updated>2008-11-26T06:03:35.791-08:00</updated><title type='text'>JavaScript ASP.NET: Reading parameters passed from another webform</title><content type='html'>This function reads the parameters that have been passed from another aspx page and sets the title name for the window depending on the value of the parameters. &lt;br /&gt;&lt;br /&gt;Invoke the JS function from : &amp;ltbody onload="loadPageTitle()"&amp;gt&lt;br /&gt;&lt;br /&gt;        function loadPageTitle()&lt;br /&gt;        {&lt;br /&gt;            var queryString = new Array();&lt;br /&gt;            var parameters = window.location.search.substring(1).split('&amp;');&lt;br /&gt;            var multiNode = false;&lt;br /&gt;            for (var i=0; i&lt;parameters.length; i++) &lt;br /&gt;            {&lt;br /&gt;                var pos = parameters[i].indexOf('=');&lt;br /&gt;                // If there is an equal sign, separate the parameter into the name and value,&lt;br /&gt;                // and store it into the queryString array.&lt;br /&gt;                if (pos &gt; 0) &lt;br /&gt;                {&lt;br /&gt;                    var paramname = parameters[i].substring(0,pos);&lt;br /&gt;                    var paramval = parameters[i].substring(pos+1);&lt;br /&gt;                    if (paramname == "nodes")&lt;br /&gt;                    { &lt;br /&gt;                        //alert("nodes:"+paramval)&lt;br /&gt;                        var nodesValue = paramval;&lt;br /&gt;                        var delimiter = nodesValue.indexOf(',');&lt;br /&gt;                        //alert("delimiter:"+delimiter);&lt;br /&gt;                        if (delimiter &gt; 0)&lt;br /&gt;                            multiNode = true;                           &lt;br /&gt;                    }&lt;br /&gt;                    else&lt;br /&gt;                    {}&lt;br /&gt;                        //alert ("this parameter name is not nodes:" + paramname);&lt;br /&gt;                    queryString[paramname] = unescape(paramval.replace(/\+/g,' '));&lt;br /&gt;                } &lt;br /&gt;                else &lt;br /&gt;                {&lt;br /&gt;                    //special value when there is a querystring parameter with no value&lt;br /&gt;                    queryString[parameters[i]]="" ;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            //alert("multinNode:" + multiNode);&lt;br /&gt;            if (!multiNode)&lt;br /&gt;            {&lt;br /&gt;                //var nodesValue = queryString["nodes"];&lt;br /&gt;                //alert("nodes:" + nodesValue );&lt;br /&gt;                var windowTitle = queryString["nodes"] + " From:" + queryString["dateFrom"] + " To:" + queryString["dateTo"];&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;                var windowTitle = queryString["plotFields"] + " From:" + queryString["dateFrom"] + " To:" + queryString["dateTo"];&lt;br /&gt;                &lt;br /&gt;            document.title = windowTitle;&lt;br /&gt;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7864064490347625379?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7864064490347625379/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7864064490347625379' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7864064490347625379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7864064490347625379'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/11/javascript-aspnet-reading-parameters.html' title='JavaScript ASP.NET: Reading parameters passed from another webform'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3239127101771190509</id><published>2008-11-26T05:42:00.000-08:00</published><updated>2008-11-26T05:49:45.859-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='progress bar'/><category scheme='http://www.blogger.com/atom/ns#' term='windows forms'/><category scheme='http://www.blogger.com/atom/ns#' term='c# .net'/><title type='text'>Windows Forms: simple progress bar</title><content type='html'>On the UI define a progress bar called progressBar1 (which monitor the whole underlying process) and second progress Bar , progressBar2, which monitors the current process. &lt;br /&gt;&lt;br /&gt;                progressBar1.Minimum = 0;&lt;br /&gt;                progressBar1.Maximum = 7;&lt;br /&gt;                progressBar1.Step = 1;&lt;br /&gt;                for (int i = 0; i &lt; 7; i++)&lt;br /&gt;                {&lt;br /&gt;                    labelCurrentProcess.Text = "Process no:" + i;&lt;br /&gt;                    progressBar2.Minimum = 0;&lt;br /&gt;                    progressBar2.Maximum = 122460;&lt;br /&gt;                    progressBar2.Value = 0;&lt;br /&gt;                    progressBar2.Step = 1;&lt;br /&gt;                    for (int j = 0; j &lt; 122460; j++)&lt;br /&gt;                    {&lt;br /&gt;                        //Do something in here&lt;br /&gt;                        progressBar2.PerformStep();&lt;br /&gt;                    }&lt;br /&gt;                    progressBar1.PerformStep();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3239127101771190509?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3239127101771190509/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3239127101771190509' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3239127101771190509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3239127101771190509'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/11/windows-forms-simple-progress-bar.html' title='Windows Forms: simple progress bar'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3039888676054294594</id><published>2008-11-26T05:39:00.000-08:00</published><updated>2008-11-26T05:42:04.770-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='windows forms'/><category scheme='http://www.blogger.com/atom/ns#' term='c# .net'/><category scheme='http://www.blogger.com/atom/ns#' term='cursor'/><title type='text'>Windows Form: Waiting cursor</title><content type='html'>this.cursor = Cursors.WaitTime;&lt;br /&gt;// do some work&lt;br /&gt;this.cursor = Cursors.Default;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3039888676054294594?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3039888676054294594/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3039888676054294594' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3039888676054294594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3039888676054294594'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/11/windows-form-waiting-cursor.html' title='Windows Form: Waiting cursor'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1256083889676367236</id><published>2008-10-24T02:36:00.000-07:00</published><updated>2008-10-24T03:38:54.689-07:00</updated><title type='text'>DataGridViewCheckBoxColumn (WinForms)</title><content type='html'>If we want to add checkboxes in a datagridView, please follow the code as in this example. There is an exmaple in MSDN that is wrong because when you run your application you get the following error: &lt;strong&gt;&lt;em&gt;"System.FormatException: Formatted value of the cell has a wrong type.To replace this default dialog please handle the dataError event" &lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is the solution that does not gives any errors and consists in moving the definition of the CellTemplate property to the top. In MSDN the assignment of this property is done after the definiton of the ThreeState property.&lt;br /&gt;&lt;br /&gt;            DataGridViewCheckBoxColumn includeGraphColumn = new DataGridViewCheckBoxColumn();&lt;br /&gt;            {&lt;br /&gt;&lt;strong&gt;                includeGraphColumn.CellTemplate = new DataGridViewCheckBoxCell();&lt;/strong&gt;                &lt;br /&gt;includeGraphColumn.HeaderText = "Include Graph";&lt;br /&gt;                includeGraphColumn.Name = "includeGraphColumn";&lt;br /&gt;                includeGraphColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;&lt;br /&gt;                includeGraphColumn.FlatStyle = FlatStyle.Standard;&lt;br /&gt;                includeGraphColumn.ThreeState = true; //true = if checkbox null/false =&gt; checkbox unchecked. False means only the value can be true or false&lt;br /&gt;                includeGraphColumn.CellTemplate.Style.BackColor = Color.Beige;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;This in fact has the same effect than creating an additonal boolean  column in the datatable that we are using to bind to our datagridView.&lt;br /&gt;&lt;br /&gt;Now if I want to make the checkbox clickable just add the CellContentClick event handler to the dataGridView:&lt;br /&gt;&lt;br /&gt;        private void gvNodes_CellContentClick(object sender, DataGridViewCellEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            object cellValue = gvNodes.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;&lt;br /&gt;            if (cellValue == null || (Boolean)cellValue == false)&lt;br /&gt;                gvNodes.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;&lt;br /&gt;            else&lt;br /&gt;                gvNodes.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;&lt;br /&gt;            //gvNodes.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = !(Boolean)(gvNodes.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);&lt;br /&gt;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1256083889676367236?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1256083889676367236/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1256083889676367236' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1256083889676367236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1256083889676367236'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/datagridviewcheckboxcolumn-winforms.html' title='DataGridViewCheckBoxColumn (WinForms)'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1802847071911584286</id><published>2008-10-17T02:20:00.000-07:00</published><updated>2008-10-17T02:27:32.654-07:00</updated><title type='text'>CHNAGE STARTUP WINFORM</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_IfN9TUWZV7U/SPhZ-zhau7I/AAAAAAAAABY/NXkWcKChsQ8/s1600-h/startup+project.bmp"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_IfN9TUWZV7U/SPhZ-zhau7I/AAAAAAAAABY/NXkWcKChsQ8/s400/startup+project.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5258051500472187826" /&gt;&lt;/a&gt;&lt;br /&gt;This is a very basic thing but I forget everytime I switch from web forms to winforms.&lt;br /&gt;Each windows project has a class called Program.cs. Click on this file and you will see:&lt;br /&gt;&lt;br /&gt;            Application.Run(new ImportFile());&lt;br /&gt;&lt;br /&gt;In this case means that our application will start running the ImportFile form. We can change this value by any other form:&lt;br /&gt;&lt;br /&gt;            Application.Run(new Main());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1802847071911584286?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1802847071911584286/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1802847071911584286' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1802847071911584286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1802847071911584286'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/chnage-startup-winform.html' title='CHNAGE STARTUP WINFORM'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_IfN9TUWZV7U/SPhZ-zhau7I/AAAAAAAAABY/NXkWcKChsQ8/s72-c/startup+project.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7563145336793252710</id><published>2008-10-16T07:51:00.000-07:00</published><updated>2008-10-16T07:58:20.372-07:00</updated><title type='text'>ZIPPING File using GZIPStream</title><content type='html'>This code zipps an XML file that is the representaion of a dataset. The file is called DataSetToDownload.xml.&lt;br /&gt;&lt;br /&gt;                  string filePath = MapPath(@"DataSetToDownload.xml");&lt;br /&gt;                  ds1.WriteXml(filePath);&lt;br /&gt;&lt;br /&gt;                  //4. Zip the dataset (limit 4GB)&lt;br /&gt;                  //------------------------------&lt;br /&gt;                  FileStream sourceFile = File.OpenRead(filePath);&lt;br /&gt;                  string fileName = @"CSV files/zippedRequest" + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + " " + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second + ".xml.gz";&lt;br /&gt;                  FileStream zippedFile = File.Create(MapPath(fileName));&lt;br /&gt;                  GZipStream compStream = new GZipStream(zippedFile, CompressionMode.Compress);&lt;br /&gt;                  byte[] bytesRead = new byte[(int)sourceFile.Length];&lt;br /&gt;                  int offset = 0;&lt;br /&gt;                  int bufferSize = 1000;&lt;br /&gt;                  int theByte = sourceFile.Read(bytesRead, offset, bufferSize);&lt;br /&gt;                  while (theByte != 0)&lt;br /&gt;                  {&lt;br /&gt;                      offset += theByte;&lt;br /&gt;                      if ((int)sourceFile.Length &gt; (offset + bufferSize))&lt;br /&gt;                          theByte = sourceFile.Read(bytesRead, offset, bufferSize);&lt;br /&gt;                      else&lt;br /&gt;                      {&lt;br /&gt;                          theByte = sourceFile.Read(bytesRead, offset, (int)sourceFile.Length - offset);&lt;br /&gt;                          theByte = 0;&lt;br /&gt;                      }&lt;br /&gt;                  }&lt;br /&gt;                  compStream.Write(bytesRead, 0, bytesRead.Length);&lt;br /&gt;                  &lt;br /&gt;                  compStream.Close();&lt;br /&gt;                  zippedFile.Close();&lt;br /&gt;                  sourceFile.Close();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7563145336793252710?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7563145336793252710/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7563145336793252710' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7563145336793252710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7563145336793252710'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/zipping-file-using-gzipstream.html' title='ZIPPING File using GZIPStream'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1234685908771384624</id><published>2008-10-16T07:38:00.000-07:00</published><updated>2008-10-16T07:44:30.200-07:00</updated><title type='text'>T-SQL USEFUL FUNCTIONS</title><content type='html'>&lt;strong&gt;TABLE VALUED FUNCTIONS: &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;1. If it is a table- valued function then invoke it as any other table&lt;br /&gt;select Data from dbo.MyFunction(par1,par2)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1. Split function &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Description&lt;/em&gt;Given an input string as well as the delimiter, it returns a table where each row has a column index with the content of the substring between the separators&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Invoke&lt;/em&gt;select Data from dbo.Split(@nodeNameList,',')&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Code&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;USE [PDMonitorEHV]&lt;br /&gt;GO&lt;br /&gt;/****** Object:  UserDefinedFunction [dbo].[Split]    Script Date: 10/16/2008 15:42:37 ******/&lt;br /&gt;SET ANSI_NULLS ON&lt;br /&gt;GO&lt;br /&gt;SET QUOTED_IDENTIFIER ON&lt;br /&gt;GO&lt;br /&gt;CREATE FUNCTION [dbo].[Split]&lt;br /&gt;(&lt;br /&gt; @RowData nvarchar(2000),&lt;br /&gt; @SplitOn nvarchar(5)&lt;br /&gt;)  &lt;br /&gt;RETURNS @RtnValue table &lt;br /&gt;(&lt;br /&gt; Id int identity(1,1),&lt;br /&gt; Data nvarchar(100)&lt;br /&gt;) &lt;br /&gt;AS  &lt;br /&gt;BEGIN &lt;br /&gt; Declare @Cnt int&lt;br /&gt; Set @Cnt = 1&lt;br /&gt;&lt;br /&gt; While (Charindex(@SplitOn,@RowData)&gt;0)&lt;br /&gt; Begin&lt;br /&gt;  Insert Into @RtnValue (data)&lt;br /&gt;  Select &lt;br /&gt;   Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))&lt;br /&gt;&lt;br /&gt;  Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))&lt;br /&gt;  Set @Cnt = @Cnt + 1&lt;br /&gt; End&lt;br /&gt; &lt;br /&gt; Insert Into @RtnValue (data)&lt;br /&gt; Select Data = ltrim(rtrim(@RowData))&lt;br /&gt;&lt;br /&gt; Return&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1234685908771384624?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1234685908771384624/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1234685908771384624' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1234685908771384624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1234685908771384624'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/t-sql-useful-functions.html' title='T-SQL USEFUL FUNCTIONS'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-2256774907547899485</id><published>2008-10-06T08:53:00.000-07:00</published><updated>2010-10-24T03:06:59.822-07:00</updated><title type='text'>Playing a sound with an asp.net application</title><content type='html'>Playing a sound on your own computer is not that difficult. The difficult with a web application is that the sound is stored on the web server and it needs to be downloaded to the local machine.&lt;br /&gt;&lt;br /&gt;There are several possibilities to do that with Javascript, but I saw an aricle on internet that explained a way to do that using .NET. It consists in creating a web custom control which in turn will be resposnsible in embedding in the HTML the sound.&lt;br /&gt;&lt;br /&gt;It is very easy. Steps:&lt;br /&gt;&lt;br /&gt;1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-2256774907547899485?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/2256774907547899485/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=2256774907547899485' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2256774907547899485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2256774907547899485'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/playing-sound-with-aspnet-application.html' title='Playing a sound with an asp.net application'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-6702722501825730312</id><published>2008-10-06T08:24:00.000-07:00</published><updated>2008-10-06T08:31:18.545-07:00</updated><title type='text'>debugging javascript with Visual Studio on local machine</title><content type='html'>&lt;a href="http://3.bp.blogspot.com/_IfN9TUWZV7U/SOovPnvkpII/AAAAAAAAABQ/wIpdgilJ8e4/s1600-h/internetoptionsdebugging.bmp"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_IfN9TUWZV7U/SOovPnvkpII/AAAAAAAAABQ/wIpdgilJ8e4/s400/internetoptionsdebugging.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5254063860694164610" /&gt;&lt;/a&gt;&lt;br /&gt;just go to Tools&gt; internet options&gt; Advanced &gt; Browsing section &gt; uncheck the following check boxes:&lt;br /&gt;Disable script debugging (Internet Explorer)&lt;br /&gt;Disable script debugging (other)&lt;br /&gt;Display a notification about every script error&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-6702722501825730312?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/6702722501825730312/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=6702722501825730312' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6702722501825730312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6702722501825730312'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/debugging-javascript-with-visual-studio.html' title='debugging javascript with Visual Studio on local machine'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_IfN9TUWZV7U/SOovPnvkpII/AAAAAAAAABQ/wIpdgilJ8e4/s72-c/internetoptionsdebugging.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-4458806833408808934</id><published>2008-10-06T05:44:00.000-07:00</published><updated>2008-10-06T07:40:18.874-07:00</updated><title type='text'>Javascript: implementing a moving separation bar</title><content type='html'>&lt;a href="http://1.bp.blogspot.com/_IfN9TUWZV7U/SOojRiv68VI/AAAAAAAAABI/7-EwEBNKAA0/s1600-h/splitter.bmp"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_IfN9TUWZV7U/SOojRiv68VI/AAAAAAAAABI/7-EwEBNKAA0/s400/splitter.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5254050699573653842" /&gt;&lt;/a&gt;&lt;br /&gt;This is the implementation of a solution in which on our left hand side we would have a a panel showing for intance a list of directories and files while in our right hand side we would have th panel showing the main information.&lt;br /&gt;What we would like to do is to be able to move the separation between both panels (like in the msdn page).&lt;br /&gt;&lt;br /&gt;Javascript file:&lt;br /&gt;&lt;br /&gt;        //global variables used to track status &lt;br /&gt;        var curWidthLeftPanel=0 &lt;br /&gt;        var curWidthSplitter = 0&lt;br /&gt;        var curPos=0 &lt;br /&gt;        var newPos=0 &lt;br /&gt;        var mouseStatus='up' &lt;br /&gt;&lt;br /&gt;        //this function gets the original div width &lt;br /&gt;        function setPos(e)&lt;br /&gt;        { &lt;br /&gt;            //for handling events in ie vs. w3c &lt;br /&gt;            curevent=(typeof event=='undefined'?e:event)&lt;br /&gt;            //alert("setPos(e)")&lt;br /&gt;            //sets mouse flag as down &lt;br /&gt;            mouseStatus='down' &lt;br /&gt;            //alert("mouseStatus=down")&lt;br /&gt;            //gets position of click &lt;br /&gt;            curPos=curevent.clientX &lt;br /&gt;            //alert("curPos=" + curPos)&lt;br /&gt;            //accepts height of the div &lt;br /&gt;            tempWidthLeftPanel=document.getElementById('ctl00_contentPlaceHolderContent_PanelTreeViewNodes').style.width&lt;br /&gt;            tempWidthSplitter=document.getElementById('splitter').style.width&lt;br /&gt;            //these lines split the height value from the 'px' units &lt;br /&gt;            //alert("tempWidthLeftPanel=" + tempWidthLeftPanel)&lt;br /&gt;            //alert("tempWidthSplitter=" + tempWidthSplitter)&lt;br /&gt;            widthArrayLeftPanel=tempWidthLeftPanel.split('p') &lt;br /&gt;            widthArraySplitter=tempWidthSplitter.split('p') &lt;br /&gt;            curWidthLeftPanel=parseInt(widthArrayLeftPanel[0]) &lt;br /&gt;            curWidthSplitter=parseInt(widthArraySplitter[0]) &lt;br /&gt;            //alert(curWidthLeftPanel)&lt;br /&gt;            //alert(curWidthSplitter)&lt;br /&gt;        } &lt;br /&gt;&lt;br /&gt;        //this changes the height of the div while the mouse button is depressed &lt;br /&gt;        function getPos(e)&lt;br /&gt;        {&lt;br /&gt;            //alert ("Hello")&lt;br /&gt;            if(mouseStatus=='down')&lt;br /&gt;            { &lt;br /&gt;                curevent=(typeof event=='undefined'?e:event) &lt;br /&gt;                //get new mouse position &lt;br /&gt;                newPos=curevent.clientX &lt;br /&gt;                //alert("newPos=" + newPos);&lt;br /&gt;                //calculate movement in pixels &lt;br /&gt;                var pxMove=parseInt(newPos-curPos) &lt;br /&gt;                //alert("pxMove=" + pxMove);&lt;br /&gt;                //determine new width &lt;br /&gt;                //alert("curWidthLeftPanel=" + curWidthLeftPanel)&lt;br /&gt;                var newWidthLeftPanel=parseInt(curWidthLeftPanel + pxMove) &lt;br /&gt;                var newSplitterPosition = parseInt(newWidthLeftPanel + 1)&lt;br /&gt;                var newWidthPlaceHolder=parseInt(newWidthLeftPanel + curWidthSplitter) &lt;br /&gt;                //alert("newWidthLeftPanel=" + newWidthLeftPanel + ";newSplitterPosition =" + newSplitterPosition + ";newWidthPlaceHolder =" + newWidthPlaceHolder)&lt;br /&gt;                //conditional to set minimum height to 5 &lt;br /&gt;                //newWidthLeftPanel=(newWidth&lt;5?5:newWidth) &lt;br /&gt;                //newWidthRightPanel=(newWidth&lt;5?5:newWidth) &lt;br /&gt;                //set the new height of the div &lt;br /&gt;                document.getElementById('ctl00_contentPlaceHolderContent_PanelTreeViewNodes').style.width=newWidthLeftPanel + 'px'&lt;br /&gt;                document.getElementById('splitter').style.left= newSplitterPosition  + 'px'&lt;br /&gt;                document.getElementById('placeHolder1').style.width = newWidthPlaceHolder + 'px' &lt;br /&gt;                //alert("newWidthLeftPanel=" + newWidthLeftPanel)&lt;br /&gt;                setCookies()&lt;br /&gt;            } &lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        function setCookies()&lt;br /&gt;        {&lt;br /&gt;         var expireDate = new Date();&lt;br /&gt;         expireDate.setMonth(expireDate.getMonth()+6)&lt;br /&gt;         var PanelTreeViewNodesWidth = document.getElementById("ctl00_contentPlaceHolderContent_PanelTreeViewNodes").style.width&lt;br /&gt;         var SplitterPosition = document.getElementById('splitter').style.left&lt;br /&gt;         var placeHolder1Width = document.getElementById('placeHolder1').style.width &lt;br /&gt;         &lt;br /&gt;         document.cookie = "PanelTreeViewNodesWidth=" + PanelTreeViewNodesWidth + ";expires=" + expireDate.toGMTString();&lt;br /&gt;         document.cookie = "SplitterPosition=" + SplitterPosition + ";expires=" + expireDate.toGMTString();&lt;br /&gt;         document.cookie = "placeHolder1Width=" + placeHolder1Width + ";expires=" + expireDate.toGMTString();&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        //this function reads the cookies only if we are in the monitor.aspx page&lt;br /&gt;        function loadControlWidth()&lt;br /&gt;        {&lt;br /&gt;            //alert('loadControlWidth()')&lt;br /&gt;            var url = location.href&lt;br /&gt;            //alert ("current url:" + url)&lt;br /&gt;            var urlSplitted = url.split("/")&lt;br /&gt;            var length = urlSplitted.length;&lt;br /&gt;            var indexLastElement = parseInt(length - 1)&lt;br /&gt;            //alert("Length:" + urlSplitted.length)&lt;br /&gt;            //alert(urlSplitted[3])&lt;br /&gt;            //alert("element:" + urlSplitted[indexLastElement])&lt;br /&gt;            if (urlSplitted[indexLastElement] == "Monitor.aspx")&lt;br /&gt;            {&lt;br /&gt;                document.getElementById("ctl00_contentPlaceHolderContent_PanelTreeViewNodes").style.width = getCookie("PanelTreeViewNodesWidth")&lt;br /&gt;             document.getElementById('splitter').style.left = getCookie("SplitterPosition")&lt;br /&gt;             document.getElementById('placeHolder1').style.width = getCookie("placeHolder1Width")             &lt;br /&gt;            }&lt;br /&gt;        } &lt;br /&gt;        &lt;br /&gt;        function getCookie(cookieName)&lt;br /&gt;        {&lt;br /&gt;         var thisCookie = document.cookie.split("; ")&lt;br /&gt;         //alert ("cookies: " + thisCookie);&lt;br /&gt;         if (document.cookie.length &amp;gt 0)&lt;br /&gt;          { &lt;br /&gt;                for (var i=0; i&amp;ltthisCookie.length; i++) &lt;br /&gt;                {&lt;br /&gt;              if (cookieName == thisCookie[i].split("=")[0]) &lt;br /&gt;              {&lt;br /&gt;               return thisCookie[i].split("=")[1]&lt;br /&gt;              }&lt;br /&gt;             }&lt;br /&gt;             return 0;&lt;br /&gt;         }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;In the HTML we make a call to the loadControlWidth function.&lt;br /&gt;&lt;br /&gt;&amp;lthead runat="server"&amp;gt&lt;br /&gt;   &amp;lttitle&amp;gtPD Monitor EHV Web Central&amp;lt/title&amp;gt&lt;br /&gt;   &amp;ltlink rel="stylesheet" type="text/css" /&amp;gt&lt;br /&gt;   &amp;ltlink href="App_Themes/Default/Stylesheet.css" rel="stylesheet" type="text/css" /&amp;gt&lt;br /&gt;   &amp;ltscript type="text/javascript" src="JavaScript/JScript1.js"&amp;gt&lt;br /&gt;        &amp;lt!-- &lt;br /&gt;        //--&amp;gt    &lt;br /&gt;   &amp;lt/script&amp;gt &lt;br /&gt;&amp;lt/head&amp;gt&lt;br /&gt;&amp;ltbody onload="loadControlWidth()"&amp;gt        &lt;br /&gt;....&lt;br /&gt;&lt;br /&gt;   &amp;ltdiv id="ContentArranger" class="ContentArranger" onmousemove="getPos(event)" onmouseup="mouseStatus='up'"&amp;gt&lt;br /&gt;      &amp;ltasp:Panel ID="PanelTreeViewNodes" style="position:absolute;top:0px;left:0px;bottom:0px;border-style:solid; border-width:1px; border-color:#E0E0E0;width:155px" runat="server" ScrollBars="Auto" Wrap="False" &amp;gt&lt;br /&gt;...&lt;br /&gt;      &amp;ltdiv id="placeHolder1" class="treeViewPlaceHolder"&amp;gt&amp;lt/div&amp;gt&lt;br /&gt;      &amp;ltdiv id="splitter" style="position:absolute;top:0px; bottom:0px;left:155px;display:block; background-color:Gray;cursor:e-resize;width:1px" onmousedown="setPos(event)"&amp;gt&amp;lt/div&amp;gt&lt;br /&gt;In this case the width of splitter + width PanelTreeViewNodes = width placeHolder1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-4458806833408808934?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/4458806833408808934/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=4458806833408808934' title='1 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4458806833408808934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4458806833408808934'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/10/javascript-implementing-moving.html' title='Javascript: implementing a moving separation bar'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_IfN9TUWZV7U/SOojRiv68VI/AAAAAAAAABI/7-EwEBNKAA0/s72-c/splitter.bmp' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1336731516777467841</id><published>2008-09-30T05:16:00.000-07:00</published><updated>2008-10-01T02:39:29.918-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='refreshing automatically'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='response.appendhandler'/><title type='text'>REFRESHING AUTOMATICALLY</title><content type='html'>Option1)Put between &amp;lthead&amp;gt and &amp;lt/head&amp;gt&lt;br /&gt;&lt;br /&gt;&amp;lthead runat="server"&amp;gt&lt;br /&gt;&amp;ltmeta equiv="Refresh" content="120;URL=http://www.mywebsite.com"&amp;gt&lt;br /&gt;&amp;lt/head&amp;gt&lt;br /&gt;&lt;br /&gt;This page is going to refresh every 120 seconds.&lt;br /&gt;At refresh time it will be redirected to the url specified. If no url is specified then it will automatically refresh the current page.&lt;br /&gt;&lt;br /&gt;Option 2) Put the following line of code in the Page_Load event_handler&lt;br /&gt;Response.AppendHeader("Refresh", &lt;br /&gt;    "10");&lt;br /&gt;This will make the webpage to refresh every 10 seconds&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1336731516777467841?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1336731516777467841/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1336731516777467841' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1336731516777467841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1336731516777467841'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/09/refreshing-automatically.html' title='REFRESHING AUTOMATICALLY'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-654819192238108852</id><published>2008-09-24T01:24:00.000-07:00</published><updated>2008-09-24T01:48:38.739-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='winform'/><category scheme='http://www.blogger.com/atom/ns#' term='c# .net'/><category scheme='http://www.blogger.com/atom/ns#' term='console application'/><title type='text'>INVOKING A CONSOLE APPLICATION FROM A WINFORM</title><content type='html'>using System.Diagnostics;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is the code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Process p = new Process();&lt;br /&gt;string path = @"..\..\..\myProject\bin\Release\myProgram.exe";&lt;br /&gt;ProcessStartInfo ps = new ProcessStartInfo(path);&lt;br /&gt;ps.UseShellExecute = false;&lt;br /&gt;p.StartInfo = ps;&lt;br /&gt;p.Start();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-654819192238108852?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/654819192238108852/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=654819192238108852' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/654819192238108852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/654819192238108852'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/09/invoking-console-application-from.html' title='INVOKING A CONSOLE APPLICATION FROM A WINFORM'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-9177507425968544476</id><published>2008-09-18T01:17:00.000-07:00</published><updated>2008-09-24T01:49:14.897-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c# .net'/><category scheme='http://www.blogger.com/atom/ns#' term='multithreading'/><category scheme='http://www.blogger.com/atom/ns#' term='backgroundworker'/><title type='text'>MULTITHREADING(I): BACKGROUNDWORKER</title><content type='html'>&lt;a href="http://1.bp.blogspot.com/_IfN9TUWZV7U/SNn31ALhezI/AAAAAAAAAA0/PMzwDlWGe4I/s1600-h/backgroundWorker.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5249499330630482738" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_IfN9TUWZV7U/SNn31ALhezI/AAAAAAAAAA0/PMzwDlWGe4I/s400/backgroundWorker.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Use the backgroundworker when you are implementing an UI and you want to invoke a process that it takes very long time. If you don't perform this process in the background then you risk that the screen looks like frozen and the user might think that the applicatiion has fallen over.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Golden rules regarding background worker:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The backgroundworker relies on few event handlers:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;DoWork event handler: is where you do all your time consuming process. Do not communicate with the UI in this event, but use the ProgressChanged event handler.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;ProgressChanged event handler: use this event to report back to the UI about the evolution of the time consuming process.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;RunWorkerCompleted event handler: use this event to report to the UI that the time consuming process has finished.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To kick off the backgroundworker invoke RunWorkerAsync&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It is not possible to change the priority of the thread in the backgroundworker.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The backgroundworker is another thread. Multithreading is not the same as having two processes working at the same time. In Multithreading the processor will split part of its time performing the main task and then will switch to perform requests that the user has made on the UI. It looks like there are 2 processes running at the same time but this is not true.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Here is an example:&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Design a UI with a progressBar (progressBar1), a Run button (buttonRun), a Cancel Button(cancelButton) and a label(label1).Notice how from the DoWork event handler invokes the ProgressChanged event every time we want this process to report to the UI:&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;public LoadingIIFFile()&lt;br /&gt;{&lt;br /&gt;InitializeComponent();&lt;br /&gt;}&lt;br /&gt;private void button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;label1.Text = "Loading...This process may take few minutes";&lt;br /&gt;backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);&lt;br /&gt;backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);&lt;br /&gt;backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);&lt;br /&gt;backgroundWorker1.RunWorkerAsync(); // kicks off backgroundworker and executes the code in DoWork&lt;br /&gt;buttonRun.Enabled = false;&lt;br /&gt;buttonCancel.Enabled = true;&lt;br /&gt;}&lt;br /&gt;private void button2_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;this.backgroundWorker1.CancelAsync();&lt;br /&gt;buttonCancel.Enabled = true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)&lt;br /&gt;{&lt;br /&gt;progressBar1.Value = e.ProgressPercentage;&lt;br /&gt;}&lt;br /&gt;private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)&lt;br /&gt;{&lt;br /&gt;if (e.Error != null)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(e.Error.Message);&lt;br /&gt;}&lt;br /&gt;else if (e.Cancelled)&lt;br /&gt;{&lt;br /&gt;label1.Text = "Cancelled";&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;label1.Text = e.Result.ToString();&lt;br /&gt;}&lt;br /&gt;buttonRun.Enabled = true;&lt;br /&gt;buttonCancel.Enabled = false;&lt;br /&gt;}&lt;br /&gt;private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)&lt;br /&gt;{&lt;br /&gt;BackgroundWorker worker = sender as BackgroundWorker;&lt;br /&gt;e.Result = LoadIIFFile(worker,e);&lt;br /&gt;}&lt;br /&gt;private string LoadIIFFile(BackgroundWorker worker, DoWorkEventArgs e)&lt;br /&gt;{&lt;br /&gt;int step = 0;&lt;br /&gt;int numberOfSteps = 4;&lt;br /&gt;int percentageCompleted = 0;&lt;br /&gt;int highestPercentageCompleted =0;&lt;br /&gt;string result = string.Empty;&lt;br /&gt;if (worker.CancellationPending)&lt;br /&gt;{&lt;br /&gt;e.Cancel = true;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;IIFFileReader iifFileReader = new IIFFileReader();&lt;br /&gt;int iNum;&lt;br /&gt;IIFFileReader.IaccBusbar iaccBusbar = new IIFFileReader.IaccBusbar();&lt;br /&gt;IIFFileReader.InfBusbar infBusbar = new IIFFileReader.InfBusbar();&lt;br /&gt;IIFFileReader.IaccLoad iaccLoad = new IIFFileReader.IaccLoad();&lt;br /&gt;IIFFileReader.InfLoad infLoad = new IIFFileReader.InfLoad();&lt;br /&gt;IIFFileReader.IaccLine iaccLine = new IIFFileReader.IaccLine();&lt;br /&gt;IIFFileReader.InfLine infLine = new IIFFileReader.InfLine();&lt;br /&gt;IIFFileReader.IaccTransformer iaccTransformer = new IIFFileReader.IaccTransformer();&lt;br /&gt;IIFFileReader.InfTransformer infTransformer = new IIFFileReader.InfTransformer();&lt;br /&gt;IIFFileReader.IaccSynMachine iaccGenerator = new IIFFileReader.IaccSynMachine();&lt;br /&gt;IIFFileReader.InfSynMachine infGenerator = new IIFFileReader.InfSynMachine();&lt;br /&gt;IIFFileReader.IaccCircuitBreaker iaccCircuitBreaker = new IIFFileReader.IaccCircuitBreaker();&lt;br /&gt;IIFFileReader.InfCircuitBreaker infCircuitBreaker = new IIFFileReader.InfCircuitBreaker();&lt;br /&gt;LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSet.tblSettingsDataTable tblSettings = new LoadingCustomersFromIIFDataSet.tblSettingsDataTable();&lt;br /&gt;LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblSettingsTableAdapter tblSettingsAdapter = new LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblSettingsTableAdapter();&lt;br /&gt;tblSettingsAdapter.Fill(tblSettings);&lt;br /&gt;//ProgramSettings settings = new ProgramSettings();&lt;br /&gt;//Open Report File&lt;br /&gt;string fileName = "Report.txt";&lt;br /&gt;FileStream filStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;BufferedStream bufStream = new BufferedStream(filStream);&lt;br /&gt;StreamWriter sWriter = new StreamWriter(bufStream);&lt;br /&gt;iNum = iifFileReader.readIIFFile(tblSettings[0].IIFFilePath);&lt;br /&gt;if (iNum == 1)&lt;br /&gt;{&lt;br /&gt;//MessageBox.Show("Loaded OK");&lt;br /&gt;//Console.WriteLine("Loaded OK");&lt;br /&gt;//Loop through busbars&lt;br /&gt;LoadingCustomersFromIIF.Program.Populate_BusBars(iifFileReader, ref iaccBusbar, ref infBusbar, sWriter);&lt;br /&gt;step = 1;&lt;br /&gt;percentageCompleted = step * 100 / numberOfSteps;&lt;br /&gt;if (percentageCompleted &gt; highestPercentageCompleted)&lt;br /&gt;{&lt;br /&gt;highestPercentageCompleted = percentageCompleted;&lt;br /&gt;worker.ReportProgress(percentageCompleted);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;LoadingCustomersFromIIFDataSet.tblCustomersDataTable tblCustomers = new LoadingCustomersFromIIFDataSet.tblCustomersDataTable();&lt;br /&gt;LoadingCustomersFromIIFDataSet.tblCustomersWithoutPlantReferenceDataTable tblCustomersWithoutPlantReference = new LoadingCustomersFromIIFDataSet.tblCustomersWithoutPlantReferenceDataTable();&lt;br /&gt;LoadingCustomersFromIIFDataSet.tblRegimesDataTable tblRegimes = new LoadingCustomersFromIIFDataSet.tblRegimesDataTable();&lt;br /&gt;LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblCustomersTableAdapter tblCustomersAdapter = new LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblCustomersTableAdapter();&lt;br /&gt;LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblCustomersWithoutPlantReferenceTableAdapter tblCustomersWithoutPlantReferenceAdapter = new LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblCustomersWithoutPlantReferenceTableAdapter();&lt;br /&gt;LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblRegimesTableAdapter tblRegimesAdapter = new LoadingCustomersFromIIF.LoadingCustomersFromIIFDataSetTableAdapters.tblRegimesTableAdapter();&lt;br /&gt;&lt;br /&gt;//Loop through loads&lt;br /&gt;//Get number of loads in network&lt;br /&gt;LoadingCustomersFromIIF.Program.Populate_Loads(iifFileReader, ref iaccLoad, ref infLoad, sWriter);&lt;br /&gt;//Loop through lines&lt;br /&gt;LoadingCustomersFromIIF.Program.Populate_Lines(iifFileReader, ref iaccLine, ref infLine, sWriter);&lt;br /&gt;step = 2;&lt;br /&gt;percentageCompleted = step * 100 / numberOfSteps;&lt;br /&gt;if (percentageCompleted &gt; highestPercentageCompleted)&lt;br /&gt;{&lt;br /&gt;highestPercentageCompleted = percentageCompleted;&lt;br /&gt;worker.ReportProgress(percentageCompleted);&lt;br /&gt;}&lt;br /&gt;LoadingCustomersFromIIF.Program.Populate_Transformers(iifFileReader, ref iaccTransformer, ref infTransformer, sWriter);&lt;br /&gt;step = 3;&lt;br /&gt;percentageCompleted = step * 100 / numberOfSteps;&lt;br /&gt;if (percentageCompleted &gt; highestPercentageCompleted)&lt;br /&gt;{&lt;br /&gt;highestPercentageCompleted = percentageCompleted;&lt;br /&gt;worker.ReportProgress(percentageCompleted);&lt;br /&gt;}&lt;br /&gt;//Loop through generators&lt;br /&gt;LoadingCustomersFromIIF.Program.Populate_Generators(iifFileReader, ref iaccGenerator, ref infGenerator, sWriter);&lt;br /&gt;step = 4;&lt;br /&gt;percentageCompleted = step * 100 / numberOfSteps;&lt;br /&gt;if (percentageCompleted &gt; highestPercentageCompleted)&lt;br /&gt;{&lt;br /&gt;highestPercentageCompleted = percentageCompleted;&lt;br /&gt;worker.ReportProgress(percentageCompleted);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Loop through circuit breakers&lt;br /&gt;//Populate_CrcuitBreakers(iifFileReader, ref iaccCircuitBreaker, ref infCircuitBreaker);&lt;br /&gt;iifFileReader.clearsystem();&lt;br /&gt;sWriter.Close();&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;result = "Error could not read the IIF file";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;result = "Records loaded successfully";&lt;br /&gt;return result;&lt;br /&gt;}&lt;br /&gt;private void LoadingIIFFile_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;label1.Text = "Ready to load records from the IIF file";&lt;br /&gt;buttonCancel.Enabled = false;&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-9177507425968544476?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/9177507425968544476/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=9177507425968544476' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/9177507425968544476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/9177507425968544476'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/09/multithreadingi-backgroundworker.html' title='MULTITHREADING(I): BACKGROUNDWORKER'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_IfN9TUWZV7U/SNn31ALhezI/AAAAAAAAAA0/PMzwDlWGe4I/s72-c/backgroundWorker.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-878708038981259975</id><published>2008-03-25T09:20:00.000-07:00</published><updated>2008-09-24T01:50:15.493-07:00</updated><title type='text'>Timeout</title><content type='html'>When executing a SQL server statment from your program we have to keep in mind that there are two types of timeouts.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1st) The one that is necessary to establish a connection.&lt;br /&gt;&lt;br /&gt;2nd) The one to retrieve all data. The default value is 30 seconds. This value might be not enough in case that we need to retrieve a big amount of data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To modify the first one is pretty easy. We just need to modify the timeout property in the command variable type.&lt;br /&gt;&lt;br /&gt;To modify the second one is easy but it requires a little bit more of code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace BatchCleansing.tblChangesDataSetTableAdapters&lt;br /&gt;{&lt;br /&gt;public partial class tblDataToCleanseTableAdapter: System.ComponentModel.Component&lt;br /&gt;{&lt;br /&gt;public int SelectCommandTimeout&lt;br /&gt;{&lt;br /&gt;get{return this.CommandCollection[0].CommandTimeout;}&lt;br /&gt;set{this.CommandCollection[0].CommandTimeout = value;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-878708038981259975?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/878708038981259975/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=878708038981259975' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/878708038981259975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/878708038981259975'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/03/timeout.html' title='Timeout'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7037547908951379382</id><published>2008-03-19T09:42:00.000-07:00</published><updated>2008-03-19T09:45:47.383-07:00</updated><title type='text'>WINFORMS LIFE CYCLE</title><content type='html'>&lt;p&gt;&lt;strong&gt;Form Startup&lt;br /&gt;&lt;/strong&gt;1. OnHandleCreated&lt;br /&gt;2. OnCreateControl&lt;br /&gt;      2.1 OnLoad&lt;br /&gt;3. OnActivated&lt;br /&gt;4. OnShown&lt;br /&gt;&lt;strong&gt;Form Shutdown&lt;/strong&gt;&lt;br /&gt;1. OnClosing&lt;br /&gt;2. OnClosed&lt;br /&gt;3. OnDeactivate&lt;br /&gt;4. OnHandleDestroyed&lt;/p&gt;&lt;p&gt;Source: &lt;a href="http://blogs.msdn.com/jaredpar/archive/2007/01/08/windows-forms-event-lifecycle.aspx"&gt;http://blogs.msdn.com/jaredpar/archive/2007/01/08/windows-forms-event-lifecycle.aspx&lt;/a&gt;&lt;br /&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7037547908951379382?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7037547908951379382/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7037547908951379382' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7037547908951379382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7037547908951379382'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/03/winforms-life-cycle.html' title='WINFORMS LIFE CYCLE'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8737763771420548631</id><published>2008-01-08T08:41:00.000-08:00</published><updated>2008-01-08T11:14:01.995-08:00</updated><title type='text'>Notes on Subversion</title><content type='html'>1. Create a a folder called "myRepository". It is recommended that the repository has the following 3 folders inside (trunk, branches, tags). The idea is that development pretty much always happens on the "Trunk" copy of the code, and where required, branches can be created in the "Branches" directory and so on.&lt;br /&gt;For instance if we have several projects we could have the following structure:&lt;br /&gt;&lt;br /&gt;/trunk/paint&lt;br /&gt;/trunk/calc&lt;br /&gt;/branches/paint&lt;br /&gt;/branches/calc&lt;br /&gt;/tags/paint&lt;br /&gt;/tags/calc&lt;br /&gt;&lt;br /&gt;or we could opt for an structure  like this one&lt;br /&gt;&lt;pre style="font-family: arial;" class="screen"&gt;/paint/trunk&lt;br /&gt;/paint/branches&lt;br /&gt;/paint/tags&lt;br /&gt;/calc/trunk&lt;br /&gt;/calc/branches&lt;br /&gt;/calc/tags&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We could have a main folder called repository (that it would be just the name of the folder) and then we could store there all repositories.&lt;br /&gt;   2. Right-click and make this folder a Repository in Subversion. The repository will not contain any file but a database of all changes that have been made in the folders that we have imported into the repository. Normally the repository will have the following structure: trunk, branches, tag. The repository normally will be located in a separated machine or server where all developpers will have access to it.&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;   3. Select the folder where we store our source code that we want to add to the "myRepository". Right-click and select Import. Browse to select the Trunk folder (or in trunk/paint if we have several projects).This will add all the information to the Repository without adding any version. This way, we have created a link between the repository and the folder containing the source code.&lt;br /&gt;   4.  Now each person in the team has to create a folder, where a copy of the source code in the Repository will be stored. This will be our workspace. Create a folder called "Checked-out". Then right-click and select Check-out. Then a copy of the files will be done in this folder.&lt;br /&gt;   6. Before starting check the latest version of the source code that we have in the repository. Right click on the "Checked-out" folder and select "Update".&lt;br /&gt;   7.   Start doing your modifications&lt;br /&gt;   8. Commit: this will update the content of the repository with the changes that we have just made.&lt;br /&gt;&lt;br /&gt;Branching/Tagging&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8737763771420548631?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8737763771420548631/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8737763771420548631' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8737763771420548631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8737763771420548631'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2008/01/notes-on-subversion.html' title='Notes on Subversion'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8242020293267961998</id><published>2007-12-12T06:34:00.000-08:00</published><updated>2007-12-13T10:26:03.165-08:00</updated><title type='text'>Events</title><content type='html'>Suppose that we have a button and we want that when somebody clicks on that button, then we display a message "Thank you for clicking me!" that will be issued from the funstion DisplayMessage.&lt;br /&gt;&lt;br /&gt;To do that with ASP.NET is very easy:&lt;br /&gt;&lt;br /&gt;First we need to define the button and which function needs to call (DisplayMessage) everytime the Cick event is raised:&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt;namespace WebApplication1&lt;br /&gt;{&lt;br /&gt;  public partial class Events : System.Web.UI.Page&lt;br /&gt;  {&lt;br /&gt;      protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;      {&lt;br /&gt;          Button bt = new Button();&lt;br /&gt;          bt.Text = "Click me!";&lt;br /&gt;          bt.Click +=new EventHandler(DisplayMessage);&lt;br /&gt;          bt.Attributes.Add("runat", "server");&lt;br /&gt;          form1.Controls.Add(bt);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      private void DisplayMessage(object sender, EventArgs e)&lt;br /&gt;      {&lt;br /&gt;          Response.Write("Thank you for clicking me");&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;Suppose that instead a button we have another object(instead of button). This object will have attached an event (like Click), that will be raised when the event (like Click) happens.&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;"&gt;In this example I have implemented an event on a file(object). Everytime a new  record is inserted into the file then a Message will be issued:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;FileTrigger.cs:&lt;/span&gt;&lt;br /&gt;This is the class where the event occur. In this case is a class to handle files.&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;namespace WebApplication1&lt;br /&gt;{&lt;br /&gt;  public delegate void FileTriggerChangedEventHandler(object sender,&lt;br /&gt;EventArgs e);&lt;br /&gt;  public class FileTrigger&lt;br /&gt;  {&lt;br /&gt;      public event FileTriggerChangedEventHandler FileChanged;&lt;br /&gt;      private FileStream filStream;&lt;br /&gt;      private BufferedStream bufStream;&lt;br /&gt;      private StreamWriter sWriter;&lt;br /&gt;&lt;br /&gt;      public FileTrigger()&lt;br /&gt;      {&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      protected virtual void OnFileChanged(EventArgs e)&lt;br /&gt;      {&lt;br /&gt;          if (FileChanged != null) // this is standard. Check if the&lt;br /&gt;somebody has hooked up a delegate to the event&lt;br /&gt;              FileChanged(this, e);&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;      public void OpenFile(string FileName)&lt;br /&gt;      {&lt;br /&gt;          filStream = new FileStream(FileName, FileMode.OpenOrCreate,&lt;br /&gt;FileAccess.Write);&lt;br /&gt;          bufStream = new BufferedStream(filStream);&lt;br /&gt;          sWriter = new StreamWriter(bufStream);&lt;br /&gt;      }&lt;br /&gt;    &lt;br /&gt;      public void AddRecord(string currentRecord)&lt;br /&gt;      {&lt;br /&gt;          sWriter.WriteLine(currentRecord);&lt;br /&gt;          sWriter.Flush();&lt;br /&gt;     //after inserting the record we call the event function &lt;br /&gt;          OnFileChanged(EventArgs.Empty);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public void CloseFileTrigger()&lt;br /&gt;      {&lt;br /&gt;          sWriter.Close();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;FileTriggerListener.cs&lt;/span&gt;&lt;br /&gt;Then  there is a "Listener" class that will listen to the event&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt;namespace WebApplication1&lt;br /&gt;{&lt;br /&gt;  public class FileEventTriggerListener&lt;br /&gt;  {&lt;br /&gt;      private FileTrigger File;&lt;br /&gt;      public string Message = "";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      public FileEventTriggerListener(FileTrigger fl)&lt;br /&gt;      {&lt;br /&gt;          File = fl;&lt;br /&gt;          File.FileChanged += new&lt;br /&gt;FileTriggerChangedEventHandler(FileChanged);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      private void FileChanged(object sender, EventArgs e)&lt;br /&gt;      {&lt;br /&gt;          this.Message = "1 record added in to the file";&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public void Detach()&lt;br /&gt;      {&lt;br /&gt;          File.FileChanged -= new&lt;br /&gt;FileTriggerChangedEventHandler(FileChanged);&lt;br /&gt;          File = null;&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;File.aspx&lt;/span&gt;&lt;br /&gt;Finally we have our ASP.NET page where the user will write the content&lt;br /&gt;of the record in a textbox.&lt;br /&gt;&lt;br /&gt;Onclick event , the text will be inserted in the Text.txt file.&lt;br /&gt;Then a message will be displayed on the screen that a record has been inserted into the file.&lt;br /&gt;&lt;br /&gt;&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="File.aspx.cs" Inherits="WebApplication1.File" %&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;br /&gt;"&amp;lt;a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html xmlns="&lt;a href="http://www.blogger.com/%20target=" _blank=""&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;" &gt;&lt;br /&gt;&amp;lt;head runat="server"&gt;&lt;br /&gt;  &amp;lt;title&gt;Untitled Page&lt;br /&gt;&amp;lt;/head&gt;&lt;br /&gt;&amp;lt;body&gt;&lt;br /&gt;  &amp;lt;form id="form1" runat="server"&gt;&lt;br /&gt;  &amp;lt;div&gt;&lt;br /&gt;      &amp;lt;asp:textbox id="TextBox1" runat="server"&gt;&lt;br /&gt;      &amp;lt;asp:Button ID="Button1" runat="server" Text="Button"&lt;br /&gt;OnClick="InsertRecord" /&gt;&lt;br /&gt;     &lt;br /&gt;&lt;br /&gt;      &lt;asp:label id="Label1" runat="server" text="Label"&gt;&lt;/asp:label&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;File.cs&lt;/span&gt;&lt;br /&gt;This is the code behind.&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt;namespace WebApplication1&lt;br /&gt;{&lt;br /&gt;  public partial class File : System.Web.UI.Page&lt;br /&gt;  {&lt;br /&gt;&lt;br /&gt;      protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;      {&lt;br /&gt;        &lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      protected void InsertRecord(object sender, EventArgs e)&lt;br /&gt;      {&lt;br /&gt;          FileTrigger ft = new FileTrigger();&lt;br /&gt;          FileEventTriggerListener listener = new&lt;br /&gt;FileEventTriggerListener(ft);&lt;br /&gt;          ft.OpenFile("Text.txt");&lt;br /&gt;          ft.AddRecord(TextBox1.Text);&lt;br /&gt;          Label1.Text = listener.Message;&lt;br /&gt;          ft.CloseFileTrigger();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8242020293267961998?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8242020293267961998/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8242020293267961998' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8242020293267961998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8242020293267961998'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/events.html' title='Events'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-4293747193378522000</id><published>2007-12-11T06:55:00.000-08:00</published><updated>2007-12-12T06:34:08.800-08:00</updated><title type='text'>Statistics tools for web development</title><content type='html'>1. google-analytics&lt;br /&gt;2. clickdensity&lt;br /&gt;3. red-eye&lt;br /&gt;4. speed-trap :  this provides all the services that red-eye and clickdensity at the same time. This could mean that we need just one request to the server to workout all the statistics and therefore could improve the performance of the website.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-4293747193378522000?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/4293747193378522000/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=4293747193378522000' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4293747193378522000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4293747193378522000'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/stattistics-tools-for-web-development.html' title='Statistics tools for web development'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7322464880719885933</id><published>2007-12-08T15:09:00.000-08:00</published><updated>2007-12-08T15:10:36.026-08:00</updated><title type='text'>Active directory - notes</title><content type='html'>1. RootDSE&lt;br /&gt;&lt;br /&gt;DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");&lt;br /&gt;String dnc = (string) rootDSE.Properties["defaultNamingContext"].Value;&lt;br /&gt;DirectoryEntry mySearchRoot = new DirectoryEntry ("LDAP://" + dnc);&lt;br /&gt;&lt;br /&gt;2. Find out tro which server are we connected:&lt;br /&gt;Ask for the dnsHostName property&lt;br /&gt;&lt;br /&gt;3. Forcing the connection to be established:&lt;br /&gt;&lt;br /&gt;Object bindTest = rootDSE.NativeObject;&lt;br /&gt;&lt;br /&gt;4. position the root in an organizational unit&lt;br /&gt;&lt;br /&gt;Test.capita.co.uk&lt;br /&gt;Schools (OU)&lt;br /&gt;School1 (OU)&lt;br /&gt;Groups (OU)&lt;br /&gt;Users (OU)&lt;br /&gt;abbot35ben&lt;br /&gt;abbot35fra&lt;br /&gt;pears20bel&lt;br /&gt;School2&lt;br /&gt;&lt;br /&gt;5. Security: we need to find out if our program can view all of the accounts. If it does not have enough permission then an empty result will be returned (I.e. no errors). One way of finding out is to establish a connection with AD with one of the 3rd party vendors and to verify if we can see the objects that we are looking for.&lt;br /&gt;&lt;br /&gt;6. Search Scope &gt; Subtree =&gt; search the current Searchroot + any chil containers&lt;br /&gt;                &gt; One Level =&gt; only immidiate children of the root (NOT the root itself). Descendants below the immiadiate children will be excluded&lt;br /&gt;                &gt; Base =&gt; only searches in the Search root object&lt;br /&gt;&lt;br /&gt;7. Filters:&lt;br /&gt;If the filter property is not specified then the default filter is used: (objectClass=*)&lt;br /&gt;Examples:&lt;br /&gt;(displayName=John Doe)&lt;br /&gt;AND(&amp;amp;) , OR(|) , NOT (!)&lt;br /&gt;&lt;br /&gt;Find an object whose attribute display Name = John Doe AND its telephone number is 5551212&lt;br /&gt;(&amp;amp;(displayName=John Doe) (telephoneNumber=5551212))&lt;br /&gt;&lt;br /&gt;(|(&amp;amp;(displayName=Joe Doe) (telephoneNumber=5551212))&lt;br /&gt;   (&amp;amp;(displayName=Mark Smith)(telephoneNumber=5551010))&lt;br /&gt;&lt;br /&gt;This search will look for an object whose display Name is Joe Doe and histelephone number 5551212 OR for another object whose displayName is Mark Smith and his telephone Numebr is 5551010.&lt;br /&gt;&lt;br /&gt;CSVE:&lt;br /&gt;To discover more LDAP attributes, go to the command prompt, type:&lt;br /&gt;CSVDE -f Exportfile.csv.  Then open Exportfile.csv with Excel.exe.   Alternatively, use ADSI Edit and right click the container objects&lt;br /&gt;Look at this example:&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;using System.DirectoryServices;&lt;br /&gt;&lt;br /&gt;public partial class _Default : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;    protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            // load users from Active Directory&lt;br /&gt;            //connect successfully to AD in css.ad.capita.co.uk: SUCCESS!&lt;br /&gt;            //----------------------------------------------------&lt;br /&gt;            //DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");&lt;br /&gt;            //String dnc = (string)rootDSE.Properties["defaultNamingContext"].Value;&lt;br /&gt;            //DirectoryEntry searchRoot = new DirectoryEntry("LDAP://" + dnc);&lt;br /&gt;            string connectionString = "LDAP://OU=Users,OU=" + TextBox3.Text + ",OU=Schools,DC=adprovisioning,DC=jrandall,DC=co,DC=uk";&lt;br /&gt;            DirectoryEntry searchRoot = new DirectoryEntry(connectionString);&lt;br /&gt;            Object bindTest = searchRoot.NativeObject;&lt;br /&gt;          &lt;br /&gt;            DirectorySearcher myDirectorySearcher = new DirectorySearcher(searchRoot);&lt;br /&gt;&lt;br /&gt;            //perform search on AD&lt;br /&gt;            //string filter = "(&amp;amp;(objectCategory=user)(objectClass=person)(mail=*)(sn=" + TextBox2.Text.Trim() + "*)(!userAccountControl:1.2.840.113556.1.4.803:=2)(givenName=" + TextBox1.Text.Trim() + "*))";&lt;br /&gt;            //string filter = "(&amp;amp;(objectClass=user)(sn=" + TextBox2.Text.Trim()+ ")(givenName=" + TextBox1.Text.Trim() +"))";&lt;br /&gt;            //string filter = "(objectClass=user)";&lt;br /&gt;            //string filter = "(&amp;amp;(objectClass=user)(OU=" + TextBox3.Text + ")(displayName=" + TextBox1.Text + " " + TextBox2.Text + "))";&lt;br /&gt;            string filter = "(&amp;amp;(objectClass=user)(objectCategory=Person)(displayName=" + TextBox1.Text + " " + TextBox2.Text + "))";&lt;br /&gt;            myDirectorySearcher.ReferralChasing = ReferralChasingOption.All;&lt;br /&gt;            myDirectorySearcher.SearchScope = SearchScope.Subtree;&lt;br /&gt;            myDirectorySearcher.Filter = filter;&lt;br /&gt;            SearchResult resultOne = myDirectorySearcher.FindOne();&lt;br /&gt;&lt;br /&gt;            if (resultOne != null)&lt;br /&gt;            {&lt;br /&gt;                //Create dataset and table to store the results&lt;br /&gt;                DataSet adDS = new DataSet();&lt;br /&gt;                DataTable adUsersDT = new DataTable("ADUsers");&lt;br /&gt;&lt;br /&gt;                DataColumn adUsersColum;&lt;br /&gt;                //adUsersColum = new DataColumn("Forename", typeof(string));&lt;br /&gt;                //adUsersDT.Columns.Add(adUsersColum);&lt;br /&gt;                //adUsersColum = new DataColumn("Surname", typeof(string));&lt;br /&gt;                //adUsersDT.Columns.Add(adUsersColum);&lt;br /&gt;                adUsersColum = new DataColumn("AdUser", typeof(string));&lt;br /&gt;                adUsersDT.Columns.Add(adUsersColum);&lt;br /&gt;               &lt;br /&gt;                DataRow adUsersRow;&lt;br /&gt;               &lt;br /&gt;                foreach (SearchResult result in myDirectorySearcher.FindAll())&lt;br /&gt;                {&lt;br /&gt;                    DirectoryEntry DirEntry = result.GetDirectoryEntry();&lt;br /&gt;                    adUsersRow = adUsersDT.NewRow();&lt;br /&gt;                    adUsersRow["AdUser"] = Convert.ToString(DirEntry.Properties["displayName"].Value);&lt;br /&gt;                    //adUsersRow["Forename"] = Convert.ToString(DirEntry.Properties["sn"].Value);&lt;br /&gt;                    //adUsersRow["Surname"] = Convert.ToString(DirEntry.Properties["givenName"].Value);&lt;br /&gt;                    adUsersDT.Rows.Add(adUsersRow);&lt;br /&gt;&lt;br /&gt;                    //Label1.Text = Convert.ToString(DirEntry.Properties["sn"].Value);&lt;br /&gt;                }&lt;br /&gt;                adDS.Tables.Add(adUsersDT);&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                Label1.Text = "Unknown User";&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            Label1.Text = ex.Message;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7322464880719885933?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7322464880719885933/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7322464880719885933' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7322464880719885933'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7322464880719885933'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/active-directory-notes.html' title='Active directory - notes'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-2115950426769536025</id><published>2007-12-07T01:50:00.001-08:00</published><updated>2007-12-07T01:51:36.608-08:00</updated><title type='text'>Which cookies do you have in your browser?</title><content type='html'>To check which cookies you have stored in your browser, type the following instruction in the address box of your browser&lt;br /&gt;javascript:alert("Cookies: "+document.cookie)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-2115950426769536025?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/2115950426769536025/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=2115950426769536025' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2115950426769536025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/2115950426769536025'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/which-cookies-do-you-have-in-your.html' title='Which cookies do you have in your browser?'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-8749776203167973682</id><published>2007-12-06T03:22:00.000-08:00</published><updated>2010-10-24T03:45:16.399-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='instance delegates'/><category scheme='http://www.blogger.com/atom/ns#' term='delegates'/><category scheme='http://www.blogger.com/atom/ns#' term='static delegates'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><title type='text'>DELEGATES</title><content type='html'>Delegates are function prototypes (signatures). By using a delegate we can call a set of functions as long the functions called has the same signature than the delegate.&lt;br /&gt;&lt;br /&gt;This is an example of multicast delegate for static methods. The multicats delegate allows us to invoke more than 1 method, or function just by calling the delegate.&lt;br /&gt;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt;namespace WebApplication1&lt;br /&gt;{&lt;br /&gt;public partial class _Default : System.Web.UI.Page&lt;br /&gt;{&lt;br /&gt;   //delegate declaration.&lt;br /&gt;   // The functions that want to used the delagate will need the same signature&lt;br /&gt;   public delegate void Display(string message);&lt;br /&gt;   protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;   {&lt;br /&gt;       Display delegateVariable = null;&lt;br /&gt;       delegateVariable += new Display(DisplayLabel); //add DisplayLabel to the delegate&lt;br /&gt;       delegateVariable += new Display(DisplayLiteral); //add DisplayLiteral to the delegate&lt;br /&gt;&lt;br /&gt;       //calling the delagate. This will execute both functions:DisplayLabel, DisplayLiteral                      &lt;br /&gt;       delegateVariable("Hello control!!");&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public static void DisplayLabel(string message)&lt;br /&gt;   {&lt;br /&gt;       //this functions prints a message on the Label control&lt;br /&gt;       Label1.Text = message;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public static void DisplayLiteral(string message)&lt;br /&gt;   {&lt;br /&gt;       //this functions prints a message on the Literal control&lt;br /&gt;       Literal1.Text = message;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;}&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is possible to create Delegates with instance methods. This is an example taken from msdn (&lt;a href="http://msdn.microsoft.com/en-us/library/900fyy8e(VS.71).aspx"&gt;http://msdn.microsoft.com/en-us/library/900fyy8e(VS.71).aspx&lt;/a&gt;) in which a static and an instance delegate is invoked:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;using System;  &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;// delegate declaration delegate void MyDelegate();  &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;public class MyClass  &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;{    &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;public void InstanceMethod()     &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;{       &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;Console.WriteLine("A message from the instance method.");&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;}     &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;static public void StaticMethod()     &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;{       &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;Console.WriteLine("A message from the static method.");&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;} &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;}  &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;public class MainClass  &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;{    &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;static public void Main()     &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;{       &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;MyClass p = new MyClass();        // Map the delegate to the instance method:       &lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;MyDelegate d = new MyDelegate(p.InstanceMethod);&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;        d();        // Map to the static method:       &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;d = new MyDelegate(MyClass.StaticMethod);&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;       d();    &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"&gt;} &lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;span class="Apple-style-span"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt;Delegates are Type Safe Pointer. This is basically because there is function that "delegates" some task to another one. This delegated function when finishes the task it returns the result to her boss. With delegates, the compiler can verify if the parameters between these two functions are of the same type as well as the result returned, so that no errors at run time can be found. &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt;Here is a more technical explanation that I retrieved from another website: &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, serif; white-space: normal; font-size: 16px; "&gt;&lt;a href="http://www.15seconds.com/issue/020815.htm"&gt;http://www.15seconds.com/issue/020815.htm&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;p style="font-size: 13px; white-space: normal; font-family: 'Arial, Helvetica,  MS Sans Serif'; "&gt;&lt;span class="clsBlurb" style="font-family: 'Arial, Helvetica,  MS Sans Serif'; font-size: 10pt; "&gt;"Delegate is commonly defined as a Type Safe Pointer. To better understand a Type-Safe pointer, let's see a how a callback function in C++/VC++ works. The Callback function is normally implemented in the &lt;a class="iAs" classname="iAs" href="http://www.15seconds.com/issue/020815.htm#" target="_blank" itxtdid="25162772" style="float: none; left: auto; right: auto; top: auto; bottom: auto; border-top-style: none; border-right-style: none; border-bottom-style: solid !important; border-left-style: none; border-width: initial; border-color: initial; background-color: transparent !important; line-height: normal; text-align: left; position: static !important; display: inline; font-family: inherit !important; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 1px !important; padding-left: 0px; font-weight: normal !important; font-size: 13px; text-decoration: underline !important; border-bottom-color: rgb(0, 100, 0) !important; border-bottom-width: 0.075em !important; color: rgb(0, 100, 0) !important; "&gt;Business&lt;/a&gt; tier of a 3-tier architecture (of course there are exceptions to that). Once the Business Logic component implements a particular functionality, say a complex arithmetic calculation, it informs a client that the job was performed successfully. In order to inform the client, it needs an address of the function\method implemented in the client. The address of a function is just a memory address; this address does not carry any information such as number of parameters, data type of each parameter and its return value. Since the Callback function does not have any idea of the Method Signature it is going to call, in short, it is not Type Safe.&lt;/span&gt;&lt;/p&gt;&lt;span class="Apple-style-span" style="font-family: 'Arial, Helvetica,  MS Sans Serif'; font-size: 13px; "&gt;However, Delegates provide the feature of Callback functions in a safe way. Taking the previous example, if the Business Logic finds that the function signature implemented by the Client differs in terms of number of parameters or parameter types or return values as opposed to the method signature, it is going to safely raise an error.&lt;/span&gt; "&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; "&gt;&lt;span class="Apple-style-span"  &gt;&lt;span class="Apple-style-span" style="font-size: 16px; white-space: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Consolas, Courier, monospace; word-break: break-all; word-wrap: break-word; font-style: normal; font-weight: normal; overflow-x: auto; overflow-y: auto; font-size: 13px; "&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-8749776203167973682?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/8749776203167973682/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=8749776203167973682' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8749776203167973682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/8749776203167973682'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/delegates.html' title='DELEGATES'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3708229722310001688</id><published>2007-12-05T06:02:00.000-08:00</published><updated>2007-12-05T06:06:07.701-08:00</updated><title type='text'>Redirecting user using Javascript</title><content type='html'>This technique can be useful to redirect users to an intermidiate page before the session timeout.&lt;br /&gt;&lt;br /&gt;    &amp;lt;head runat="server" id="Head"&amp;gt;   &lt;br /&gt;    &amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;    &amp;lt;!--&lt;br /&gt;    function delayer()&lt;br /&gt;    {&lt;br /&gt;        setTimeout("redirect()",1200000)    &lt;br /&gt;    }&lt;br /&gt;    function redirect()&lt;br /&gt;    {&lt;br /&gt;        document.location = "../CustomerService/SessionExpired.aspx"&lt;br /&gt;    }&lt;br /&gt;    //--&gt;&lt;br /&gt;    &amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&gt;&lt;br /&gt;&amp;lt;body class="leapfrog" onload="delayer()"&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3708229722310001688?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3708229722310001688/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3708229722310001688' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3708229722310001688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3708229722310001688'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/redirecting-user-using-javascript.html' title='Redirecting user using Javascript'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1001743850637875208</id><published>2007-12-04T02:50:00.000-08:00</published><updated>2007-12-04T03:13:54.519-08:00</updated><title type='text'>Injecting Javascript in ASP.NET</title><content type='html'>This is a customer complaint webform. The user enters some text that can't be longer than 5,000 characters. A Javascript function counts while the user is typing them. Another function keeps the number of characters to the value entered when coming back from another page.&lt;br /&gt;Steps:&lt;br /&gt;1. store the script in a string&lt;br /&gt;2. register the script. We can use two methods:&lt;br /&gt;           Page.ClientScript.RegisterStartupScript &gt; this will put the script on the top of the page&lt;br /&gt;           Page.ClientScript.RegisterClientScriptBlock &gt; this will put the script at the bottom of the page&lt;br /&gt;3. Apply the events when the script needs to be fired&lt;br /&gt;           ComplaintGenericTextBox.Input.Attributes.Add("onKeyDown", theFunction);&lt;br /&gt;           ComplaintGenericTextBox.Input.Attributes.Add("onKeyUp", theFunction);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                                 &amp;lt;npower:generictextbox id="ComplaintGenericTextBox" runat="server" labeltext="* Your complaint" FieldName="complaint" Required="true"&amp;gt;&lt;br /&gt;                                   &amp;lt;Label CssClass="mandatory"&amp;gt;&amp;lt;/Label&amp;gt;                     &lt;br /&gt;                                   &amp;lt;Input TextMode="MultiLine" Rows="7" Columns="50" maxlength="5000" /&amp;gt;&lt;br /&gt;                               &amp;lt;/npower:generictextbox&amp;gt;&lt;br /&gt;                               &amp;lt;npower:GenericHelpTrigger runat="server" id="GenericHelpTrigger1" Text="Click to display help" AssociatedControlId="GenericHelp1" /&amp;gt;                                                               &lt;br /&gt;                               &amp;lt;npower:GenericHelp runat="server" id="GenericHelp1" HelpText="Please provide as much information  as possible to help us understand your enquiry." /&amp;gt;&lt;br /&gt;                           &amp;lt;/div&amp;gt;&lt;br /&gt;                           &amp;lt;p&amp;gt;You have &amp;lt;input readonly="readonly" type="text" name="remLen" size="4" maxlength="4" value="5000" style="border:none;" /&amp;gt;characters left to type&amp;lt;/p&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;              string script = @"&amp;lt;script language=javascript&amp;gt;&lt;br /&gt;                                   function textCounter(field, countfield, maxlimit)&lt;br /&gt;                                   {&lt;br /&gt;                                       if (field.value.length &gt; maxlimit)&lt;br /&gt;                                           field.value = field.value.substring(0, maxlimit);&lt;br /&gt;                                       else&lt;br /&gt;                                           countfield.value = maxlimit - field.value.length;&lt;br /&gt;                                   }&lt;br /&gt;                               &amp;lt;/script&gt;";&lt;br /&gt;           string postScript = @"&lt;br /&gt;                                &amp;lt;script language='javascript'&amp;gt;&lt;br /&gt;                                           textCounter( aspnetForm." + ComplaintGenericTextBox.Input.ClientID + @",aspnetForm.remLen ,5000);&lt;br /&gt;                                &amp;lt;/script&amp;gt;                              &lt;br /&gt;                               ";&lt;br /&gt;           Page.ClientScript.RegisterStartupScript(this.GetType(), "ClientScriptFunction1", postScript);&lt;br /&gt;           Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientScriptFunction", script);&lt;br /&gt;&lt;br /&gt;           string theFunction = "javascript:textCounter(" + ComplaintGenericTextBox.Input.ClientID + ",this.form.remLen,5000);";&lt;br /&gt;&lt;br /&gt;           ComplaintGenericTextBox.Input.Attributes.Add("onKeyDown", theFunction);&lt;br /&gt;           ComplaintGenericTextBox.Input.Attributes.Add("onKeyUp", theFunction);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1001743850637875208?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1001743850637875208/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1001743850637875208' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1001743850637875208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1001743850637875208'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/injecting-javascript-in-aspnet.html' title='Injecting Javascript in ASP.NET'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-519392399192650388</id><published>2007-12-04T02:45:00.000-08:00</published><updated>2007-12-04T02:50:13.403-08:00</updated><title type='text'>Send Emails ASP.NET</title><content type='html'>&lt;pre class="code"&gt;This example is from http://support.microsoft.com/?scid=kb%3Ben-us%3B310273&amp;amp;x=10&amp;amp;y=14&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Mail;&lt;br /&gt;&lt;br /&gt;namespace WebMail&lt;br /&gt;{&lt;br /&gt;  class Class1&lt;br /&gt;  {&lt;br /&gt;      static void Main(string[] args)&lt;br /&gt;      {&lt;br /&gt;          try&lt;br /&gt;          {&lt;br /&gt;              MailMessage oMsg = new MailMessage();&lt;br /&gt;              // TODO: Replace with sender e-mail address.&lt;br /&gt;              oMsg.From = "sender@somewhere.com";&lt;br /&gt;              // TODO: Replace with recipient e-mail address.&lt;br /&gt;              oMsg.To = "recipient@somewhere.com";&lt;br /&gt;              oMsg.Subject = "Send Using Web Mail";&lt;br /&gt;            &lt;br /&gt;              // SEND IN HTML FORMAT (comment this line to send plain text).&lt;br /&gt;              oMsg.BodyFormat = MailFormat.Html;&lt;br /&gt;            &lt;br /&gt;              // HTML Body (remove HTML tags for plain text).&lt;br /&gt;              oMsg.Body = "&lt;b&gt;Hello World!&lt;/b&gt;";&lt;br /&gt;            &lt;br /&gt;              // ADD AN ATTACHMENT.&lt;br /&gt;              // TODO: Replace with path to attachment.&lt;br /&gt;              String sFile = @"C:\temp\Hello.txt";&lt;br /&gt;              MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);&lt;br /&gt;&lt;br /&gt;              oMsg.Attachments.Add(oAttch);&lt;br /&gt;&lt;br /&gt;              // TODO: Replace with the name of your remote SMTP server.&lt;br /&gt;              SmtpMail.SmtpServer = "MySMTPServer";&lt;br /&gt;              SmtpMail.Send(oMsg);&lt;br /&gt;&lt;br /&gt;              oMsg = null;&lt;br /&gt;              oAttch = null;&lt;br /&gt;          }&lt;br /&gt;          catch (Exception e)&lt;br /&gt;          {&lt;br /&gt;              Console.WriteLine("{0} Exception caught.", e);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;} &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-519392399192650388?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/519392399192650388/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=519392399192650388' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/519392399192650388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/519392399192650388'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/12/send-emails-aspnet.html' title='Send Emails ASP.NET'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3839449820128304142</id><published>2007-08-22T03:09:00.000-07:00</published><updated>2009-06-18T05:23:53.775-07:00</updated><title type='text'>BUILD / REBUILD /CLEAN</title><content type='html'>I took this definition from a post:&lt;br /&gt;"&lt;strong&gt;Rebuild&lt;/strong&gt; builds all parts of a project or solution regardless of changes to agiven part.&lt;strong&gt;Build&lt;/strong&gt; (in theory) builds only those part of a project the *have changed*since the last build".&lt;br /&gt;&lt;br /&gt;When we compile a solution Visual studio creates folders (debug/bin) and files (for instance can copy assemblies from one directory to another).&lt;br /&gt;&lt;br /&gt;When we Clean the solution, VS deletes all this files and folders that have been created during the compilation process.&lt;br /&gt;If after a claen we rebuild the solution, all these files and folders will be recreated.&lt;br /&gt;If we make a small change that doesn't require to add any new file or doesn't affect the folders that VS has already created then a Build has to be enough.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3839449820128304142?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3839449820128304142/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3839449820128304142' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3839449820128304142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3839449820128304142'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/build-or-rebuild.html' title='BUILD / REBUILD /CLEAN'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-6187341269334586345</id><published>2007-08-14T06:35:00.000-07:00</published><updated>2007-08-14T06:41:18.929-07:00</updated><title type='text'>DATABASE SCHEMA</title><content type='html'>Here is an example:&lt;br /&gt;&lt;br /&gt;/* db audit schema */&lt;br /&gt;USE master;&lt;br /&gt;GO&lt;br /&gt;IF DB_ID (N'leapfrogAudit') IS NOT NULL&lt;br /&gt;    DROP DATABASE leapfrogAudit;&lt;br /&gt;GO&lt;br /&gt;CREATE DATABASE leapfrogAudit;&lt;br /&gt;GO&lt;br /&gt;use leapfrogAudit;&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblQueries', 'U') IS NOT NULL &lt;br /&gt;     DROP TABLE dbo.tblQueries&lt;br /&gt;GO&lt;br /&gt;create table tblQueries&lt;br /&gt;([reference_id] int IDENTITY(1,1) primary key clustered not null,&lt;br /&gt;[time_stamp] timestamp not null);&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblCustomer', 'U') IS NOT NULL &lt;br /&gt;    DROP TABLE dbo.tblCustomer&lt;br /&gt;GO&lt;br /&gt;create table tblCustomer&lt;br /&gt;([customer_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;[title] varchar(50) not null,&lt;br /&gt;[firstname] varchar(50) not null,&lt;br /&gt;[lastname] varchar(50) not null,&lt;br /&gt;[reference_id] int not null references tblQueries(reference_id));&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblContact', 'U') IS NOT NULL&lt;br /&gt;    DROP TABLE dbo.tblContact&lt;br /&gt;GO&lt;br /&gt;create table tblContact&lt;br /&gt;([contact_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;[address] varchar(50) not null,&lt;br /&gt;[postCode] varchar(50) not null,&lt;br /&gt;[town] varchar(50) not null,&lt;br /&gt;[customer_id] int not null references tblCustomer(customer_id));&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblBankAccount', 'U') IS NOT NULL &lt;br /&gt;   DROP TABLE dbo.tblBankAccount&lt;br /&gt;GO&lt;br /&gt;create table tblBankAccount&lt;br /&gt;([bankAccount_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;[accountNumber] varchar(50) not null,&lt;br /&gt;[sortcode] varchar(50) not null,&lt;br /&gt;[customer_id] int not null references tblCustomer(customer_id));&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblPayment', 'U') IS NOT NULL &lt;br /&gt;     DROP TABLE dbo.tblPayment&lt;br /&gt;GO&lt;br /&gt;create table tblPayment&lt;br /&gt;([payment_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;[amount] money not null,&lt;br /&gt;payment_date smalldatetime not null,&lt;br /&gt;comment varchar(50) not null,&lt;br /&gt;customer_id int not null references tblCustomer(customer_id));&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblMeter', 'U') IS NOT NULL &lt;br /&gt;    DROP TABLE dbo.tblMeter&lt;br /&gt;GO&lt;br /&gt;create table tblMeter&lt;br /&gt;([meterReading_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;[meterReading] varchar(50) not null,&lt;br /&gt;[superTariffReading] varchar(50) not null,&lt;br /&gt;[customer_id] int not null references tblCustomer(customer_id));&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblAccount', 'U') IS NOT NULL &lt;br /&gt;     DROP TABLE dbo.tblAccount&lt;br /&gt;GO&lt;br /&gt;create table tblAccount&lt;br /&gt;([account_no] varchar(50) not null primary key clustered,&lt;br /&gt;[fuel_type] varchar(50) not null,&lt;br /&gt;[customer_id] int not null references tblCustomer(customer_id));&lt;br /&gt;GO&lt;br /&gt;create table tblEnquiryType&lt;br /&gt;([enquiryType_id] varchar(50) not null primary key clustered,&lt;br /&gt;[enquiryReason] varchar(50) not null);&lt;br /&gt;GO&lt;br /&gt;IF OBJECT_ID('dbo.tblCustomerService', 'U') IS NOT NULL &lt;br /&gt;    DROP TABLE dbo.tblCustomerServiceGO&lt;br /&gt;create table tblCustomerService&lt;br /&gt;    ([customerService_id] int IDENTITY(1,1) not null primary key clustered,&lt;br /&gt;     [fromType] varchar(50) not null,&lt;br /&gt;     [fuelType] varchar(50) not null,&lt;br /&gt;     [enquiryType_Id] varchar(50) not null references tblEnquiryType(enquiryType_id),&lt;br /&gt;     [query] varchar(50) not null,&lt;br /&gt;     [account_no] varchar(50) not null references tblAccount(account_no));&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-6187341269334586345?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/6187341269334586345/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=6187341269334586345' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6187341269334586345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6187341269334586345'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/database-schema.html' title='DATABASE SCHEMA'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-6806290039313662382</id><published>2007-08-14T06:30:00.000-07:00</published><updated>2007-08-15T02:56:26.256-07:00</updated><title type='text'>STORED PROCEDURES</title><content type='html'>Here is an example:&lt;br /&gt;&lt;br /&gt;USE leapfrogAudit;&lt;br /&gt;GO&lt;br /&gt;CREATE PROCEDURE sp_InsertMeterReading&lt;br /&gt;@title varchar(50),&lt;br /&gt;@firstName varchar(50),&lt;br /&gt;@lastName varchar(50),&lt;br /&gt;@electricMeterReading varchar(50),&lt;br /&gt;@superTariffReading varchar(50),&lt;br /&gt;@refId int OUTPUTASBEGIN&lt;br /&gt;--Insert tblQuerys&lt;br /&gt;INSERT INTO tblQueries(time_stamp)VALUES(GetDate());&lt;br /&gt;--Select the last reference_id&lt;br /&gt;DECLARE @referenceId int;&lt;br /&gt;SET @referenceId = (SELECT MAX(reference_id) FROM tblQueries);&lt;br /&gt;SELECT @refId = @referenceId;&lt;br /&gt;--Insert tblCustomer&lt;br /&gt;INSERT INTO tblCustomer(title, firstName, LastName, reference_id) VALUES (@title,@firstName,@lastName,@referenceId);&lt;br /&gt;--Insert tblMeter&lt;br /&gt;DECLARE @CustomerId int;&lt;br /&gt;SET @CustomerId = (SELECT MAX(customer_id) FROM tblCustomer);&lt;br /&gt;INSERT INTO tblMeter(meterreading,supertariffreading,customer_id) VALUES (@electricMeterReading,@superTariffReading,@CustomerId);&lt;br /&gt;END&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Calling Stored Procedure&lt;br /&gt;&lt;/strong&gt;1. Calling stored Procedure with output parameters:&lt;br /&gt;&lt;br /&gt;use leapFrogAudit;&lt;br /&gt;DECLARE @refId int;&lt;br /&gt;EXECUTE sp_InsertMeterReading 'Mr','John','Littlewoods','12345','12345',@refId OUTPUT;&lt;br /&gt;SELECT @refId;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;1. Begin - End:&lt;/strong&gt; this is a sign that a set of statements will be executed. Each statement has to finish with a ';'.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;TroubleShooting:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;1. If copying a Stored Procedure from Notepad, we can get errors because of bad formatting.Go to previous line. Click on Delete. Click on enter and Tab.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-6806290039313662382?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/6806290039313662382/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=6806290039313662382' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6806290039313662382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6806290039313662382'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/stored-procedures.html' title='STORED PROCEDURES'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3746525957470853003</id><published>2007-08-09T06:21:00.000-07:00</published><updated>2007-08-09T06:22:17.988-07:00</updated><title type='text'>DICTIONARY Class .NET 2.0</title><content type='html'>This is a new Class for .NET 2.0.&lt;br /&gt;It uses generics to improve the HashTable.&lt;br /&gt;Source: &lt;a href="http://msdn2.microsoft.com/en-us/library/xfhwa508(vs.80).aspx"&gt;http://msdn2.microsoft.com/en-us/library/xfhwa508(vs.80).aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;&lt;br /&gt;public class Example&lt;br /&gt;{&lt;br /&gt;    public static void Main()&lt;br /&gt;    {&lt;br /&gt;        // Create a new dictionary of strings, with string keys.&lt;br /&gt;        //&lt;br /&gt;        Dictionary&lt;string,&gt; openWith =&lt;br /&gt;            new Dictionary&lt;string,&gt;();&lt;br /&gt;&lt;br /&gt;        // Add some elements to the dictionary. There are no&lt;br /&gt;        // duplicate keys, but some of the values are duplicates.&lt;br /&gt;        openWith.Add("txt", "notepad.exe");&lt;br /&gt;        openWith.Add("bmp", "paint.exe");&lt;br /&gt;        openWith.Add("dib", "paint.exe");&lt;br /&gt;        openWith.Add("rtf", "wordpad.exe");&lt;br /&gt;&lt;br /&gt;        // The Add method throws an exception if the new key is&lt;br /&gt;        // already in the dictionary.&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            openWith.Add("txt", "winword.exe");&lt;br /&gt;        }&lt;br /&gt;        catch (ArgumentException)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("An element with Key = \"txt\" already exists.");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // The Item property is another name for the indexer, so you&lt;br /&gt;        // can omit its name when accessing elements.&lt;br /&gt;        Console.WriteLine("For key = \"rtf\", value = {0}.",&lt;br /&gt;            openWith["rtf"]);&lt;br /&gt;&lt;br /&gt;        // The indexer can be used to change the value associated&lt;br /&gt;        // with a key.&lt;br /&gt;        openWith["rtf"] = "winword.exe";&lt;br /&gt;        Console.WriteLine("For key = \"rtf\", value = {0}.",&lt;br /&gt;            openWith["rtf"]);&lt;br /&gt;&lt;br /&gt;        // If a key does not exist, setting the indexer for that key&lt;br /&gt;        // adds a new key/value pair.&lt;br /&gt;        openWith["doc"] = "winword.exe";&lt;br /&gt;&lt;br /&gt;        // The indexer throws an exception if the requested key is&lt;br /&gt;        // not in the dictionary.&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("For key = \"tif\", value = {0}.",&lt;br /&gt;                openWith["tif"]);&lt;br /&gt;        }&lt;br /&gt;        catch (KeyNotFoundException)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Key = \"tif\" is not found.");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // When a program often has to try keys that turn out not to&lt;br /&gt;        // be in the dictionary, TryGetValue can be a more efficient&lt;br /&gt;        // way to retrieve values.&lt;br /&gt;        string value = "";&lt;br /&gt;        if (openWith.TryGetValue("tif", out value))&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("For key = \"tif\", value = {0}.", value);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Key = \"tif\" is not found.");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // ContainsKey can be used to test keys before inserting&lt;br /&gt;        // them.&lt;br /&gt;        if (!openWith.ContainsKey("ht"))&lt;br /&gt;        {&lt;br /&gt;            openWith.Add("ht", "hypertrm.exe");&lt;br /&gt;            Console.WriteLine("Value added for key = \"ht\": {0}",&lt;br /&gt;                openWith["ht"]);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // When you use foreach to enumerate dictionary elements,&lt;br /&gt;        // the elements are retrieved as KeyValuePair objects.&lt;br /&gt;        Console.WriteLine();&lt;br /&gt;        foreach( KeyValuePair&lt;string,&gt; kvp in openWith )&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Key = {0}, Value = {1}",&lt;br /&gt;                kvp.Key, kvp.Value);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // To get the values alone, use the Values property.&lt;br /&gt;        Dictionary&lt;string,&gt;.ValueCollection valueColl =&lt;br /&gt;            openWith.Values;&lt;br /&gt;&lt;br /&gt;        // The elements of the ValueCollection are strongly typed&lt;br /&gt;        // with the type that was specified for dictionary values.&lt;br /&gt;        Console.WriteLine();&lt;br /&gt;        foreach( string s in valueColl )&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Value = {0}", s);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // To get the keys alone, use the Keys property.&lt;br /&gt;        Dictionary&lt;string,&gt;.KeyCollection keyColl =&lt;br /&gt;            openWith.Keys;&lt;br /&gt;&lt;br /&gt;        // The elements of the KeyCollection are strongly typed&lt;br /&gt;        // with the type that was specified for dictionary keys.&lt;br /&gt;        Console.WriteLine();&lt;br /&gt;        foreach( string s in keyColl )&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Key = {0}", s);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        // Use the Remove method to remove a key/value pair.&lt;br /&gt;        Console.WriteLine("\nRemove(\"doc\")");&lt;br /&gt;        openWith.Remove("doc");&lt;br /&gt;&lt;br /&gt;        if (!openWith.ContainsKey("doc"))&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Key \"doc\" is not found.");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* This code example produces the following output:&lt;br /&gt;&lt;br /&gt;An element with Key = "txt" already exists.&lt;br /&gt;For key = "rtf", value = wordpad.exe.&lt;br /&gt;For key = "rtf", value = winword.exe.&lt;br /&gt;Key = "tif" is not found.&lt;br /&gt;Key = "tif" is not found.&lt;br /&gt;Value added for key = "ht": hypertrm.exe&lt;br /&gt;&lt;br /&gt;Key = txt, Value = notepad.exe&lt;br /&gt;Key = bmp, Value = paint.exe&lt;br /&gt;Key = dib, Value = paint.exe&lt;br /&gt;Key = rtf, Value = winword.exe&lt;br /&gt;Key = doc, Value = winword.exe&lt;br /&gt;Key = ht, Value = hypertrm.exe&lt;br /&gt;&lt;br /&gt;Value = notepad.exe&lt;br /&gt;Value = paint.exe&lt;br /&gt;Value = paint.exe&lt;br /&gt;Value = winword.exe&lt;br /&gt;Value = winword.exe&lt;br /&gt;Value = hypertrm.exe&lt;br /&gt;&lt;br /&gt;Key = txt&lt;br /&gt;Key = bmp&lt;br /&gt;Key = dib&lt;br /&gt;Key = rtf&lt;br /&gt;Key = doc&lt;br /&gt;Key = ht&lt;br /&gt;&lt;br /&gt;Remove("doc")&lt;br /&gt;Key "doc" is not found.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3746525957470853003?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3746525957470853003/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3746525957470853003' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3746525957470853003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3746525957470853003'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/dictionary-class-net-20.html' title='DICTIONARY Class .NET 2.0'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-4787547824316238114</id><published>2007-08-09T04:08:00.000-07:00</published><updated>2007-08-09T04:10:23.687-07:00</updated><title type='text'>C#.NET 2.0 Generics</title><content type='html'>&lt;ol&gt;&lt;li&gt;GENERICS&lt;br /&gt;&lt;br /&gt;In few words, Generics allow us to implement classes that are of generic type, and that means that that class can handle any type of data.&lt;br /&gt;&lt;br /&gt;For instance we could define a Stack class, but instead of defining a stack for integers, a stack for decimals, a stack for strings, generics allow us to define a class, whose type it is not specified on the definition of the class but only when we use it. To do that we provide a parameter to the class between the &lt;&gt; symbols.&lt;br /&gt;&lt;br /&gt;Exmaple:&lt;br /&gt;&lt;br /&gt;Public Class Stack &lt;t&gt;&lt;br /&gt;{&lt;br /&gt;            T[] m_items;&lt;br /&gt;            public void Push () { }&lt;br /&gt;            public T Pop() { }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Stack &lt;int&gt; myStack = new Stack&lt;int&gt;();&lt;br /&gt;myStack.Push(1);&lt;br /&gt;myStack.Push(2);&lt;br /&gt;int number = myStack.Pop()&lt;br /&gt;&lt;br /&gt;In this case we have defined a generic stack that later we have decided to use it to store integers. We could have created another one to store Strings.&lt;br /&gt;&lt;br /&gt; In .NET 1.1 we could implement such a stack with the object  type. Look at this example:&lt;br /&gt;&lt;br /&gt;public class Stack&lt;br /&gt;{&lt;br /&gt;   object[] m_Items;&lt;br /&gt;   public void Push(object item)&lt;br /&gt;   {...}&lt;br /&gt;   public object Pop()&lt;br /&gt;   {...}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Stack stack = new Stack()&lt;br /&gt;Stack.Push(1);&lt;br /&gt;Stack.Push(2);&lt;br /&gt;Int number = (int)stack.Pop()&lt;br /&gt;&lt;br /&gt;But using the object type has loads of inconveniences:&lt;br /&gt;&lt;br /&gt;Issue Performance: When using value types, you have to box them in order to push and store them, and unbox the value types when popping them off the stack. Boxing and unboxing incurs a significant performance penalty in their own right, but it also increases the pressure on the managed heap, resulting in more garbage collections, which is not great for performance either. Even when using reference types instead of value types, there is still a performance penalty because you have to cast from an Object to the actual type you interact with and incur the casting cost.&lt;br /&gt;&lt;br /&gt;Type safety when Casting objects: Because the compiler lets you cast anything to and from Object, you lose compile-time type safety. In other words, the compiler does not complain about our coding but we don’t have the certainty that the code won’t give us a run-time error. For example, the following code compiles fine, but raises an invalid cast exception at run time:&lt;br /&gt;&lt;br /&gt;Stack stack = new Stack()&lt;br /&gt;Stack.Push(1);&lt;br /&gt;Stack.Push(2);&lt;br /&gt;// This line compiles but will throw an exception&lt;br /&gt;string number = (string)stack.Pop()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another possibility to get around this problem is define a Stack Class integer, a Stack class string, etc, but this is not very practical and it could be difficult to maintain.&lt;br /&gt;&lt;br /&gt;OTHER EXAMPLES&lt;br /&gt;&lt;br /&gt;1.       We can define structs with generics:&lt;br /&gt;Public struct Point &lt;t&gt;&lt;br /&gt;{&lt;br /&gt;    public T x;&lt;br /&gt;    public T y;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; Point &lt;int&gt; point;&lt;br /&gt; point.x = 1;&lt;br /&gt; point.y = 2;&lt;br /&gt;&lt;br /&gt;Point &lt;double&gt; point;&lt;br /&gt; point.x = 1.1;&lt;br /&gt; point.y = 2.1;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.       If we have defined a Generic class in C#.NET  we can call that class from a VB.NET.&lt;br /&gt;3.       Default(T): for example the Pop() in the stack, when it is empty, if we want ot return the default value that is stored in the stack we can do that with generics. For string type stack it will return null while for integers it will return 0.&lt;br /&gt;&lt;br /&gt;Public T Pop()&lt;br /&gt;{&lt;br /&gt;m_StackPointer --;&lt;br /&gt;if (m_StackPointer &gt;=0)&lt;br /&gt;{&lt;br /&gt;//return the current value&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;m_StackPointer = 0;&lt;br /&gt;return default(T);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; &lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-4787547824316238114?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/4787547824316238114/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=4787547824316238114' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4787547824316238114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/4787547824316238114'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/cnet-20-generics.html' title='C#.NET 2.0 Generics'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7211185235888430281</id><published>2007-08-08T05:58:00.000-07:00</published><updated>2007-08-08T07:08:48.618-07:00</updated><title type='text'>UML Structural Modelling Diagrams</title><content type='html'>&lt;a href="http://3.bp.blogspot.com/_IfN9TUWZV7U/RrnOLlexxpI/AAAAAAAAAAs/RC8upDUGosw/s1600-h/packageclasses.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5096331151781512850" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_IfN9TUWZV7U/RrnOLlexxpI/AAAAAAAAAAs/RC8upDUGosw/s400/packageclasses.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_IfN9TUWZV7U/RrnN8VexxoI/AAAAAAAAAAk/ka2imaR8Xis/s1600-h/packageclasses.bmp"&gt;&lt;/a&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;strong&gt;Packages&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Blocks containg normally classes. Each package in general represents a namespace.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Class diagrams&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Association Diagrams: they implement relationship between classes&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Generalization: they implement inheritance between classes.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Aggregation: example: an AddressBook parent class is made up of 2 smaller components (the Contact and ContactGroup classes). There is a &lt;em&gt;composite &lt;/em&gt;aggregation between AddressBook and their children becauase if we delete the AddressBook class we'll need to delete their children class (Contact and ContactGroup). This type of relationship is modelled with a black diamond.In Enterprise Architect this is called &lt;em&gt;Composition&lt;/em&gt;. On the other hand if we delete ContactGroup, it doesn't mean that we are deleteing a Contact. This is called in Enterprise Architect as &lt;em&gt;Aggregation.&lt;/em&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Realization: implements abstract classes and interfaces where the child class implements the methods of the parent class.&lt;/li&gt;&lt;/ol&gt;&lt;strong&gt;Object Diagrams&lt;br /&gt;&lt;/strong&gt;&lt;p&gt;They show relationship between objects and can be useful to clrify the reltionship beween their classes.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Component Diagram&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Components are similar to packages but they offer more a more semantically grouping mechanism.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Deployment Diagram&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Show the hardware elements (&lt;em&gt;Nodes&lt;/em&gt;) and the software (in the broad sense: executables, files, electronic documents,etc) that is implemented on top of this hardware (&lt;em&gt;Artifact&lt;/em&gt;). Just remember that we can use the Nodes sterotypes to implement common useful nodes such as CD ROM, Server, PC , PC Client, etc.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7211185235888430281?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7211185235888430281/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7211185235888430281' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7211185235888430281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7211185235888430281'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/uml-structural-modelling-diagrams.html' title='UML Structural Modelling Diagrams'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_IfN9TUWZV7U/RrnOLlexxpI/AAAAAAAAAAs/RC8upDUGosw/s72-c/packageclasses.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-6727161886752713072</id><published>2007-08-06T01:52:00.000-07:00</published><updated>2007-08-06T01:59:02.720-07:00</updated><title type='text'>TRANSACTIONS</title><content type='html'>Note: this is a summary from the following article: &lt;a href="http://aspnet.4guysfromrolla.com/articles/072705-1.aspx"&gt;http://aspnet.4guysfromrolla.com/articles/072705-1.aspx&lt;/a&gt;&lt;br /&gt;Transaction = group of SQL sentences executed as one.&lt;br /&gt;Steps:&lt;br /&gt;&lt;br /&gt;1. Indicate that you want to start the transaction. All commands from this point forward are part of the logical, atomic operation.&lt;br /&gt;2. Issue the discrete commands - the INSERT, UPDATE, and DELETEs that make up your transaction.&lt;br /&gt;3. If any of these commands cause an error, rollback the transaction. Rolling back a transaction has the effect of undoing the effects of all previous statements in the transaction.&lt;br /&gt;4. If all steps succeed, commit the transaction. This persists the changes made throughout the transaction to the database.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;em&gt;'Create a connection&lt;br /&gt;&lt;/em&gt;Dim myConnection As New SqlConnection(myConnString)&lt;br /&gt;myConnection.Open()&lt;br /&gt;'Start the transaction&lt;br /&gt;Dim myTrans As SqlTransaction = myConnection.BeginTransaction()&lt;br /&gt;Try  &lt;br /&gt;&lt;em&gt;'Specify the first statement to run...   &lt;/em&gt;&lt;br /&gt;Dim sql as String = "INSERT INTO ..."  &lt;br /&gt;&lt;em&gt;'Create the SqlCommand object, specifying the transaction through   &lt;/em&gt;&lt;br /&gt;&lt;em&gt;'the constructor (along with the SQL string and SqlConnection)   &lt;/em&gt;&lt;br /&gt;&lt;em&gt;'Alternatively, could set properties of myCommand   &lt;/em&gt;&lt;br /&gt;&lt;em&gt;'to specify the Connection, CommandText, and Transaction...   &lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;/em&gt;&lt;br /&gt;Dim myCommand as New SqlCommand(sql, myConnection, myTrans)&lt;br /&gt;myCommand.ExecuteNonQuery()     &lt;br /&gt;&lt;em&gt;'Issue another INSERT   &lt;/em&gt;&lt;br /&gt;myCommand.CommandText = "INSERT INTO ..."  &lt;br /&gt;myCommand.ExecuteNonQuery()     &lt;br /&gt;&lt;em&gt;'... Lather, rinse, repeat as needed! ...   &lt;/em&gt;&lt;br /&gt;&lt;em&gt;'If we reach here, all command succeeded, so commit the transaction   &lt;/em&gt;&lt;br /&gt;myTrans.Commit  &lt;br /&gt;Catch ex as Exception  &lt;br /&gt;&lt;em&gt;'Something went wrong, so rollback the transaction   &lt;/em&gt;&lt;br /&gt;myTrans.Rollback()    &lt;br /&gt;Throw 'Bubble up the exceptionFinally  &lt;br /&gt;myConnection.Close()&lt;br /&gt;&lt;em&gt;'Finally, close the connection&lt;/em&gt;&lt;br /&gt;End Try&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-6727161886752713072?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/6727161886752713072/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=6727161886752713072' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6727161886752713072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/6727161886752713072'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/08/transactions.html' title='TRANSACTIONS'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-7460134093472202379</id><published>2007-07-17T09:39:00.000-07:00</published><updated>2007-07-17T09:42:00.120-07:00</updated><title type='text'>Reflector</title><content type='html'>Reflector is an utility that allow us to browse compiled classes.&lt;br /&gt;Can be downloaded from &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;http://www.aisto.com/roeder/dotnet/&lt;/a&gt;&lt;br /&gt;If we run it we will be able to see the content of the compiled assemblies in .NET containing classes and its implementation.&lt;br /&gt;We can also see the classes that we have implemented by just dragging the content in the temporary files to the Reflector. The temporary compilation would be in a place like:&lt;br /&gt;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\workbench\32912f1e\5b43d3c6&lt;br /&gt;&lt;br /&gt;Pick up a .dll and drag it to the Reflector. With Reflector we can see the implementation generated automatically either in C#.NET or VB.NET. We can see as well how the IL (Intermidiate Language) looks like for a specific class in the dll.&lt;br /&gt;&lt;br /&gt;Note: the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files folder contains a copy of our applications that we have in our current working folder.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-7460134093472202379?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/7460134093472202379/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=7460134093472202379' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7460134093472202379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/7460134093472202379'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/07/reflector.html' title='Reflector'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-1333819633147805387</id><published>2007-07-17T08:18:00.000-07:00</published><updated>2007-08-13T08:16:24.563-07:00</updated><title type='text'>StringBuilder Class</title><content type='html'>If we are going to work on a pragram that manages loads of strings, mainly appending them, we should choose this class instead of string, because it manages in a more efficient way the memory allocated to the strings.&lt;br /&gt;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;StringBuilder mysb = new StringBuilder("Hello");&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;MessageBox.Show("Capacity:" + mysb.Capacity);&lt;br /&gt;MessageBox.Show("Max Capacity:" + mysb.MaxCapacity);&lt;br /&gt;MessageBox.Show("Length:" + mysb.Capacity);&lt;br /&gt;&lt;br /&gt;mysb.Append(" World");//appends World to append&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;MessageBox.Show("Capacity:" + mysb.Capacity);&lt;br /&gt;MessageBox.Show("Max Capacity:" + mysb.MaxCapacity);&lt;br /&gt;MessageBox.Show("Length:" + mysb.Capacity);&lt;br /&gt;&lt;br /&gt;mysb.Insert(6, " little"); //insert "little" after World&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;&lt;br /&gt;mysb.Replace("little", "big");&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;&lt;br /&gt;mysb.Remove(6,3); //remove big&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;&lt;br /&gt;mysb.Append("my friend"); //capacity doubles&lt;br /&gt;MessageBox.Show(Convert.ToString(mysb));&lt;br /&gt;MessageBox.Show("Capacity:" + mysb.Capacity);&lt;br /&gt;MessageBox.Show("Max Capacity:" + mysb.MaxCapacity);&lt;br /&gt;MessageBox.Show("Length:" + mysb.Capacity);&lt;br /&gt;&lt;br /&gt;mysb.EnsureCapacity(25); //keeps the capacity at 25&lt;br /&gt;MessageBox.Show("Capacity:" + mysb.Capacity);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-1333819633147805387?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/1333819633147805387/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=1333819633147805387' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1333819633147805387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/1333819633147805387'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/07/stringbuilder-class.html' title='StringBuilder Class'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-3499281749801840253</id><published>2007-07-11T23:42:00.000-07:00</published><updated>2007-07-12T01:04:00.726-07:00</updated><title type='text'>Webservices</title><content type='html'>&lt;strong&gt;Creating a WebService&lt;/strong&gt;&lt;br /&gt;select project. Add&gt;new WebSite&gt;ASP.NET Web Service. Call this WebService "Service". Then a service.asmx and a service.cs file will be created. Insert your code in Service.cs.&lt;br /&gt;&lt;br /&gt;Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Services;&lt;br /&gt;using System.Web.Services.Protocols;&lt;br /&gt;//Dataset&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;[WebService(Namespace = "http://tempuri.org/")]&lt;br /&gt;[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]&lt;br /&gt;public class Service : System.Web.Services.WebService&lt;br /&gt;{&lt;br /&gt;public Service ()&lt;br /&gt;{&lt;br /&gt;//Uncomment the following line if using designed components&lt;br /&gt;//InitializeComponent();&lt;br /&gt;}&lt;br /&gt;[WebMethod]&lt;br /&gt;public string HelloWorld()&lt;br /&gt;{&lt;br /&gt;return "Hello World";&lt;br /&gt;}&lt;br /&gt;[WebMethod]&lt;br /&gt;public DataSet getClients()&lt;br /&gt;{&lt;br /&gt;DataSet objDS = new DataSet();&lt;br /&gt;DataTable objDT = new DataTable();&lt;br /&gt;DataColumn objDC;&lt;br /&gt;DataRow objDR;&lt;br /&gt;objDC = new DataColumn("AccountId", Type.GetType("System.String"));&lt;br /&gt;objDT.Columns.Add(objDC);&lt;br /&gt;objDC = new DataColumn("Forename", Type.GetType("System.String"));&lt;br /&gt;objDT.Columns.Add(objDC);&lt;br /&gt;objDC = new DataColumn("Surname", Type.GetType("System.String"));&lt;br /&gt;objDT.Columns.Add(objDC);&lt;br /&gt;objDC = new DataColumn("AccountNumber", Type.GetType("System.String"));&lt;br /&gt;objDT.Columns.Add(objDC);&lt;br /&gt;objDR = objDT.NewRow();&lt;br /&gt;objDR["AccountId"] = "1";&lt;br /&gt;objDR["Forename"] = "Marc";&lt;br /&gt;objDR["Surname"] = "Costa";&lt;br /&gt;objDR["AccountNumber"] = "10000";&lt;br /&gt;objDT.Rows.Add(objDR);&lt;br /&gt;objDR = objDT.NewRow();&lt;br /&gt;objDR["AccountId"] = "2";&lt;br /&gt;objDR["Forename"] = "Laura";&lt;br /&gt;objDR["Surname"] = "Jenkins";&lt;br /&gt;objDR["AccountNumber"] = "10001";&lt;br /&gt;objDT.Rows.Add(objDR);&lt;br /&gt;objDS.Tables.Add(objDT);&lt;br /&gt;return objDS;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Consuming the Webservice&lt;/strong&gt;&lt;br /&gt;Go to Add Web Reference&gt; choose where your webservice is located. In our case we will choose Web Services in this solution.&lt;br /&gt;&lt;br /&gt;A list of webservices in the solution will be displayed. Select the one that we are interested in. We will see a list of functions that this webservice can return. Click on the function and try it to check that is working. Once this has been verified we can give a name to this webservice in the Web reference name textbox. For instance Service. Click on Add Reference. If everything is allright we will see that a new folder has been added into Add_webreferences, called netService, and that wil contain the following files: Service.disco, Service.discomap, Service.wsdl.&lt;br /&gt;&lt;br /&gt;After that we can use this webservice in our code:&lt;br /&gt;&lt;br /&gt;netService.Service objWS = new netService.Service(); //declares the object&lt;br /&gt;objDS = objWS.getClients(); //invokes the webservice function.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-3499281749801840253?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/3499281749801840253/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=3499281749801840253' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3499281749801840253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/3499281749801840253'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/07/webservices.html' title='Webservices'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5806124225165493233.post-138980514488567646</id><published>2007-07-11T07:51:00.000-07:00</published><updated>2007-08-08T07:10:00.043-07:00</updated><title type='text'>Nunit</title><content type='html'>To run NUnit in .NET 2.0 we have to go to: Start&gt;Programs&gt;NUnit GUI (NET 2.0). If we click on the icon on the desktop it runs by default 1.1 version.&lt;br /&gt;To use NUnit we need first of all to add a reference into the project. From Visual Studio select Add Reference&gt;Browse&gt;Program Files&gt;NUnit 2.4.1&gt;bin&gt;nunit.framework.dll&lt;br /&gt;&lt;br /&gt;What to test?&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Boundary conditions (extreme situations. Big numbers, divide by zero,...)&lt;/li&gt;&lt;li&gt;Test for Success and fail.&lt;/li&gt;&lt;li&gt;Test general functionality&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Here is an example of a class that I have created that tests the calculator class:&lt;br /&gt;&lt;/p&gt;&lt;div align="left"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;strong&gt;using NUnit.Framework&lt;/strong&gt;;&lt;br /&gt;namespace Nunit_test&lt;br /&gt;{&lt;br /&gt;[TestFixture]&lt;br /&gt;public class Class1&lt;br /&gt;{&lt;br /&gt;private Calulator calculator;&lt;br /&gt;public Class1()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;[SetUp()]&lt;br /&gt;public void Init()&lt;br /&gt;{&lt;br /&gt;//code at the start of each test&lt;br /&gt;calculator = new Calulator();&lt;br /&gt;}&lt;br /&gt;[TearDown]&lt;br /&gt;public void Clean()&lt;br /&gt;{&lt;br /&gt;//code after each test case.&lt;br /&gt;//we could dispose the object for instance&lt;br /&gt;}&lt;br /&gt;//test cases are here.&lt;br /&gt;[Test]&lt;br /&gt;public void TestAddMethod()&lt;br /&gt;{&lt;br /&gt;int result = calculator.Add(2, 2);&lt;br /&gt;Assert.AreEqual(4, result);&lt;br /&gt;}&lt;br /&gt;[Test]&lt;br /&gt;public void TestSubtractMethod()&lt;br /&gt;{&lt;br /&gt;int result = calculator.Subtract(2, 2);&lt;br /&gt;Assert.AreEqual(0,0);&lt;br /&gt;}&lt;br /&gt;[Test]&lt;br /&gt;[ExpectedException(typeof(DivideByZeroException))]&lt;br /&gt;public void TestDivideByZeroMethod()&lt;br /&gt;{&lt;br /&gt;float result = calculator.Divide(1, 0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[Test]&lt;br /&gt;[Ignore]&lt;br /&gt;public void TestAddFailure()&lt;br /&gt;{&lt;br /&gt;int result = calculator.Add(2, 2);&lt;br /&gt;//Assert.Assert(result != 1);&lt;br /&gt;}&lt;br /&gt;[Test]&lt;br /&gt;[Ignore("Implementation not complete yet")]&lt;br /&gt;public void TestMultiplyMethod()&lt;br /&gt;{&lt;br /&gt;}&lt;/div&gt;&lt;div align="left"&gt; &lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Run Nunit&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;Open the NUnit&gt; File&gt; Open&gt; look for the executable project for the class implemented above.&lt;/div&gt;&lt;div align="left"&gt;We will see our test cases in a tree. Click on Run.&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Troubleshooting&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Error message: System.BadImageFormatException: version 2.0 is not a compatible version&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;this message is because NUnit is running under 1.1 while your program has been implemented in 2.0. Open the right version of NUnit. Start&gt;Programs&gt;NUnit&gt;GUI (Net 2.0)&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;which version of NUnit am I running? &lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;Go to help&gt;About NUnit and check the CLR version.&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;All test cases have been ignored. Fixture class is not public.&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;make sure that your class/method that you want to test is PUBLIC.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5806124225165493233-138980514488567646?l=iloveaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iloveaspnet.blogspot.com/feeds/138980514488567646/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5806124225165493233&amp;postID=138980514488567646' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/138980514488567646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5806124225165493233/posts/default/138980514488567646'/><link rel='alternate' type='text/html' href='http://iloveaspnet.blogspot.com/2007/07/nunit.html' title='Nunit'/><author><name>Marc Costa</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
