国产探花免费观看_亚洲丰满少妇自慰呻吟_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.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彩票| 连平县| 专栏| 堆龙德庆县| 吴川市| 七台河市| 天长市| 封开县| 察雅县| 高台县| 兴和县| 南昌县| 高密市| 怀集县| 曲阜市| 丰都县| 大英县| 上饶县| 泾川县| 宜黄县| 墨脱县| 甘南县| 梁河县| 平度市| 聂拉木县| 英山县| 姚安县| 龙陵县| 隆化县| 郸城县| 那坡县| 临沧市| 东平县| 建德市| 崇明县| 华蓥市| 道孚县| 林周县| 大足县| 宜州市| 绥宁县|