- 热门文章:
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--7
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--9
- · 转转: ASP 内建对象Request和Respones
- · 关于.net的自定义控件(请各位大虾指正)
- · 转: ASP.NET高级应用 (2)
- · 转: ASP.NET高级应用 (1)
- · 转: ASP.NET高级应用 (3)
- · DPC: Creating a multicolumn Dropdownlist[等级:初 中]
- · DPC:Hiding Columns In A DataGrid[等级:初 中]
- · DPC:Creating a DataBound List of Radio Buttons--PART1[等级:中]
- · DPC:Creating a DataBound List of Radio Buttons--PART2[等级:中]
- · DPC:Creating a DataBound List of Radio Buttons--预览页面source code[等级:中]
上一篇:回答讨饭猫之asp.net优化(一) >>
Common ASP.NET Code Techniques (DPC&DWC Reference)--8
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.
相关文章:
- · .NET几大热点问题(转)
- · DataList控件也玩分页 (转自aspcn.com)
- · 用 StringBuilder 类替代 String
- · 杂志目录(页面部分CodeBehind)
- · 杂志目录(数据库访问部分)
- · 杂志目录(页面部分)
- · 推荐一个免费的CSharp编辑器
- · 使用JScript.NET创建asp.net页面(二)
- · 使用JScript.NET创建asp.net页面(三)
- · 使用JScript.NET创建asp.net页面(四)
- · 使用JScript.NET创建asp.net页面(五)
- · 使用JScript.NET创建asp.net页面(六)
- · 使用JScript.NET创建asp.net页面(七)
- · 有好东西不要自己藏着,拿出来大家分享啊,这是我的:关于bate2的MD5加密方法.
- · 转:ASP.NET验证控件详解
- · 在ASP.NET中获取文件属性
- · datalist分页(codebehind部分)
- · datalist分页(cj168.DataAccess.MagsDB中的2个方法)
- · datalist分页(页面部分)
- · .net beta2 操作cookie的例子(转)
- · 如何在DataGrid控件中隐藏列
- · Common ASP.NET Code Techniques (DPC&DWCReference)--1
- · Common ASP.NET Code Techniques (DPC&dwc Reference)--2
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--3
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--4
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--5
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--6
- · 在datagrid中删除时确定(精华区的补充)
- · Displaying ListView items - with class! by Rob Birdwell
- · 一个带checkbox的webcontrol
- · 保护 XML Web 服务免受黑客攻击 [第一部分]
- · 保护 XML Web 服务免受黑客攻击, [第二部分]
- · treeview的源代码
- · 在datagrid中删除时确定?(转)
- · vs.net beta 2中利用DataGrid分页详解
- · COM组件对象与.NET类对象的相互转换
- · 关于DataGrid对象的属性设置(VB)
- · XmlNodeList
