Imports System.IO Public Class CreateFile Inherits System.Web.UI.Page Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList Protected WithEvents btnDelete As System.Web.UI.WebControls.Button Protected WithEvents btnCreate As System.Web.UI.WebControls.Button Protected WithEvents btnDisplay As System.Web.UI.WebControls.Button Protected WithEvents Label3 As System.Web.UI.WebControls.Label Protected WithEvents Label1 As System.Web.UI.WebControls.Label #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Dim MyPath As String Dim MyFile As String Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here MyPath = "c:\Inetpub\wwwroot\Chapter12\Users\" If Not Page.IsPostBack Then Label1.Text = _ "Enter the name of the file to create." Call DisplayFiles(MyPath) DropDownList1.Visible = False btnDelete.Visible = False btnDisplay.Visible = False Label3.Visible = False Else DropDownList1.Visible = True btnDelete.Visible = True btnDisplay.Visible = True Label3.Visible = True Try MyFile = MyPath & DropDownList1.SelectedItem.ToString Catch exc As NullReferenceException Catch exc As ArgumentNullException End Try Call DisplayFiles(MyPath) End If End Sub Public Function DisplayFiles(ByVal MyPath) Dim DDL As DirectoryInfo = _ New DirectoryInfo(MyPath) Dim MyFile As FileInfo Dim MyHash As New Hashtable For Each MyFile In DDL.GetFiles() MyHash.Add(MyFile.Name, MyFile.Name) Next DropDownList1.DataTextField = "Key" DropDownList1.DataValueField = "Value" DropDownList1.DataSource = MyHash DropDownList1.DataBind() End Function Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click Try ' Insert the code here Label1.Text = "The " & TextBox1.Text & _ " file was created successfully." Catch exc As ArgumentException Label1.Text = "You must enter a valid name to create a file." Catch exc As ArgumentNullException Label1.Text = "You must enter a name to create a file." Catch exc As IOException Label1.Text = "The file already exists." Catch exc As PathTooLongException Label1.Text = "The file name is to long." End Try TextBox1.Text = "" DisplayFiles(MyPath) End Sub Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Try ' Insert the code here Catch exc As ArgumentNullException Label1.Text = "You must specify a file to delete." Catch exc As NullReferenceException Label1.Text = "You must specify a file to delete." Catch exc As UnauthorizedAccessException Label1.Text = "You are not authorized to delete this file." End Try TextBox1.Text = "" DisplayFiles(MyPath) End Sub Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Label3.Text = "" Try ' Insert the code here Catch exc As ArgumentNullException Label1.Text = "You must select a file that exists." End Try DisplayFiles(MyPath) End Sub End Class