Articles on C# programming language.

Spawning A Process in C#

The sample application has two parts. The first part starts a notepad process when you click the ‘Start’ (Marked as 1) button. You can enter the text document location in the text box (Marked as 2) before clicking the start button. When a text document is specified, the notepad process opens that document.

In the second part, the example app runs the batch as a process when we click the start button (Marked as 7). The batch file performs a ‘DOS Copy’ operation, which requires Source and Destination locations. We can supply these data can through two text boxes (Marked as 3 & 4). When a batch file execution continues, we can see a console window in the background. The checkbox ‘Make Silent’ (marked as 5) suppresses the background command window. The checkbox ‘Notify when closed’ (Marked as 6) when checked, allows the application receiving the notification when process finished its operation. In our case, when the batch file completes the copy action, our example gets a notification.

Multiple Result Sets Processing in Ado.net

In this Example, we will see packing more than one SQL statement in a SqlCommand and process it through the SqlDataReader object. From the past articles on ado.net we are already familiar with Connection, Command and Reader objects. Hence, we will focus on dealing with multiple result sets.

The example retrieves the data from the SQL Server sample database Pubs. A total number of authors queried from the table authors is displayed in a label control marked as 1 and author name from the same table is displayed in the combo box item marked as 2. The list box marked as 3 displays all store names by querying the table stores from the Pubs database. When we click the Get Data button (Marked as 4), the example fetches all the data through a single SqlCommand formed by three SQL statements.

Dynamically Changing Web Themes In Asp.Net

When we start this example website, it first displays the home page. We can select a product and submit it to move to the Order Confirmation page. The order confirmation page has labels to provide order confirmation and the same page also has a link called ‘Home’ to navigate back to the homepage. From the homepage, we can navigate to the Web Admin Page where we can set the theme for the entire website. We can select a theme in the web admin page and apply that theme to the whole site (In our case it contains only three pages) by clicking the ‘apply’ button. From the web admin page, we can go to the main web page by using the home link.

All three pages use two themes named Ocean and Desert. By default, when we launch the site for the first time, we do not apply any theme. So we should go to the web admin page and from there we can apply a theme. The code behind in the web admin page uses the session variable for demo purpose. You should use application variables for real websites.

AppSettings – Dynamically Adding & Updating

In the last article, we saw how to use the app.config file, its hierarchy, and preference in picking the App settings. In this article, we will see updating the app.config file at runtime. The article example shows adding, deleting and updating a Key-Value entry in the appSettings Section of app.config file. Note, all the settings related to the App goes under the appSettings section.

In the above example, the result of the action performed on the App.config file is passed on to the user through the ‘Display Area’. To add (Button Marked as 5) a setting to the app.config file, the key and value should be keyed-in in the Setting Key, Setting Value text boxes marked as 2 and 3 in the screenshot. The user should mention the key in the Setting Key text box to get (Marker 6) the AppSetting entry from the ‘App.Config’. We show the retrieved key in the display area and in the Setting value. To adjust (Through button marker 7) an existing setting, the user will point out the existing key and changed value in the Setting Key and Setting Value, respectively. To delete (Marker 8) a key, the user will specify it in the Setting Key. Note we do all these actions at run time.

Understanding & Using AppConfig File

Let us say we are writing an Internet modem device monitor service application. The duty of the application will be tracking for Upload and download action of the modem. When there is a large download say 500KB per second for past 10 Minutes, the device should assert that to a user. The intimation can be done either by blinking a Red LED in the modem device or by making continues beep or by making the entire desktop with a red transparent overlay. But which option the utility should choose from? Now I hear you are saying keep it as an ‘Application Setting’. In C#, it is AppConfig file.

In old days, Legacy windows desktop software uses section-based Initialization Config Files (‘INI Files’) and App reads and writes from it. The coder places the settings on sections, which are nothing but organizing the settings under a certain group. Now in dot net days, Microsoft replaced the INI files as AppConfig files. They place the App settings in the XML format in application config files aka AppConfig file. In this article, we will explore how to make use of the AppConfig file. For exploring, we will create a simple C# Windows Form based example.