官术网_书友最值得收藏!

Starting a process from a web page

What we will do in this chapter is to learn how to open, for example, Notepad and then explore directly from a page. For this, go to Default.aspx, and enter the Design view. Double-click on the Show button. This takes us into Default.aspx.cs.

Delete the Page_Load block, so that it looks like the screen shown in Figure 5.5.1:

Figure 5.5.1: The initial Default.aspx.cs code for this project

First, below the using System line, enter the following:

using System.Collections.Generic;

You add this line because we are dealing with dictionaries. Then, add one more line below this:

using System.Diagnostics;

You will see shortly why this line is needed. This is how you can start a process. A process, for example, refers to Notepad.

Now, between the set of curly braces beneath the line beginning with protected void Button1_Click..., enter the following:

Dictionary<string, string> filePrograms = new Dictionary<string, string>();

Hover your mouse over Dictionary and look at the pop-up tip, as shown in Figure 5.5.2. Do you see where it says TKey? This indicates the type of key, and TValue specifies the type of value. In our case, both will be of the string type:

Figure 5.5.2: Pop-up tip for Dictionary

Note that we give the dictionary a name such as filePrograms. Next, to make memory for it, enter new Dictionary<string, string> to indicate the type of key and the type of value and close this with a semicolon.

In the next stage, we will fill this dictionary. So, enter the following directly below this line:

filePrograms.Add("notepad.exe", @"c:\data\samplefile.txt");
主站蜘蛛池模板: 锡林郭勒盟| 疏勒县| 石林| 旅游| 凤城市| 新昌县| 马鞍山市| 应用必备| 庆阳市| 普定县| 天等县| 建昌县| 湾仔区| 防城港市| 浮山县| 正宁县| 颍上县| 云南省| 大庆市| 桐柏县| 海城市| 平武县| 青田县| 哈尔滨市| 庄河市| 沙坪坝区| 稻城县| 张家口市| 东山县| 沂南县| 修文县| 阿巴嘎旗| 界首市| 永康市| 木兰县| 安丘市| 石嘴山市| 高雄县| 鄂伦春自治旗| 诸城市| 通州区|