国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Common ASP.NET Code Techniques (DPC&DWC Refere

2024-07-10 12:58:12
字體:
來源:轉載
供稿:網友
國內最大的酷站演示中心!
figure 2.7
output of listing 2.2.1 when viewed through a browser.

when working with the various file system classes, it is often handy to import the system.io namespace to save unneeded typing (line 1).

listing 2.2.1 uses the postback form technique we discussed in chapter 1, "common asp.net page techniques." on line 74, a form with the runat="server" attribute is created. in the form, there is an asp:textbox control and a submit button (btnsubmit, line 77). when a user first visits the page, page.ispostback is false and lines 5 and 6 in the page_load event handler are executed, displaying an instructional message.

after the user enters a directory name and submits the form, the page.ispostback property is set to true and the code from lines 8 through 39 is executed. on line 9, a directoryinfo object, dirinfo, is created. because the directoryinfo class is useful for retrieving information on a particular directory, including the files and subdirectories of a particular directory, it isn't surprising that the directoryinfo constructor requires, as a parameter, the path of the directory with which the developer is interested in working. in this case, we are interested in the directory specified by the user in the txtdirectoryname text box.


--------------------------------------------------------------------------------

note

the directoryinfo class represents a specific directory on the web server's file system; the directoryinfo constructor requires that you specify a valid directory path. however, there may be times when you don't want to have to go through the steps of creating an instance of the directoryinfo class just to, say, delete a directory. the .net framework contains a directory class for this purpose. this class cannot be instantiated and, instead, contains a number of static methods that can be used to work with any directory. we'll examine this class later in this section.


--------------------------------------------------------------------------------

after we've created an instance of the directoryinfo class, we can access its methods and properties. however, what if the user specified a directory that does not exist? such a case would generate an unsightly runtime error. to compensate for this, we use a try ... catch block, nesting the calls to the directoryinfo classes properties and methods inside the try block (lines 13 through 33). if the directory specified by the user doesn't exist, a directorynotfoundexception exception will be thrown. the catch block starting on line 34 will then catch this exception and an error message will be displayed. figure 2.8 shows the browser output when a user enters a nonexistent directory name.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平乡县| 蒲城县| 腾冲县| 翁源县| 峨边| 阳春市| 上高县| 康平县| 富宁县| 如东县| 五指山市| 河北省| 长治县| 海宁市| 阜阳市| 鄯善县| 林西县| 朝阳区| 英吉沙县| 裕民县| 英德市| 云和县| 尼木县| 绥棱县| 丘北县| 景洪市| 察隅县| 汪清县| 内黄县| 西乡县| 襄汾县| 孝昌县| 武宁县| 广德县| 明星| 五华县| 军事| 乌兰察布市| 股票| 改则县| 定结县|