<html>
<title>第九例 HtmlInputCheckBox和HtmlInputFile控件使用</title>
 <head>
 
    <script language="VB" runat="server">
       Sub Button1_Click(Source As Object, e As EventArgs)
           
	If Check1.Checked = True Then
'判断是否HtmlInputCheck被选中
            If Text1.Value = "" Then
                Span1.InnerHtml = "错误：你必须键入一个文件名"
                Return
            End If
            
            If Not (File1.PostedFile Is Nothing) Then
                Try
                    File1.PostedFile.SaveAs(("c:\temp\" + Text1.Value))
'如果上传成功，显示成功信息
                    Span1.InnerHtml = "文件成功的上传到 <b>c:\\temp\\" & _
                                      Text1.Value & "</b> Web服务器上"
                Catch exc As Exception
                    Span1.InnerHtml = "文件没有保存到 <b>c:\\temp\\" & _
                                      Text1.Value & "</b><br>" & exc.ToString()
                End Try
            End If
	  else
'如果没有选中HtmlInputCheck，则不会返回文件上传信息
		 If Text1.Value = "" Then
                  Return
            End If
            
            If Not (File1.PostedFile Is Nothing) Then
                File1.PostedFile.SaveAs(("c:\temp\" + Text1.Value))
                
            End If
	End if
	    
        End Sub 
    </script>
 
 </head>
 <body>
 
    <h3><font face="Verdana">第九例 HtmlInputCheckBox和HtmlInputFile控件使用</font></h3>
 
    <form enctype="multipart/form-data" runat="server">
 
       选择一个文件上传: 
       <input id="File1" 
              type="file" 
              runat="server">
 
       <p>
       保存文件名字 (不需要路径): 
       <input id="Text1" 
              type="text" 
              runat="server">
 
       <p>
       <span id=Span1 
             style="font: 8pt verdana;" 
             runat="server" />
 
       <p>
	<input id="Check1" type=checkbox runat="server" checked/> 
            显示文件上传信息 &nbsp;&nbsp;

       <input type=button 
              id="Button1" 
              value="Upload" 
              OnServerClick="Button1_Click" 
              runat="server">
 
    </form>
 
 </body>
 </html>