<%@ Import Namespace="System.IO" %>
<html>
<head>
<script language="VB" runat="server">
dim filesize as integer
dim message,filepath As String
Sub Button1_Click(sender As Object, e As EventArgs)
Span1.InnerHtml=""
if File1.PostedFile.FileName="" then
  Span1.InnerHtml ="<script language=javascript>alert('Please select one file.');</"+"script>"
  return
else
  filesize=File1.PostedFile.ContentLength
  if filesize>(1024*1024) then
  Span1.InnerHtml ="<script language=javascript>alert('Sorry,file size exceed the limit 1M ');</"+"script>"
  return   
  end if
   If Not IsNothing(File1.PostedFile) Then   
            filepath = cStr(Request.physicalapplicationpath &"AspSimpleUpload\uploads\"& Path.GetFileName(File1.PostedFile.FileName))
'response.Write(File.Exists(filepath))
 if File.Exists(filepath) then
 ' message="<scrip"+"t language=javascript>{if(confirm('Sorry,File already exists,is replace?')) {document.fileup.saveit.value='1';}}</"+"script>"
 'response.Write(message)
 'Span1.InnerHtml =message
 'response.Write(saveit.value)
 'return
 if replace.checked then
  Try
File1.PostedFile.SaveAs(filepath)
Span1.InnerHtml = "<script language=javascript>alert('File successfully written to disk!');</"+"script>"
return
 Catch Exc As Exception
Span1.InnerHtml = "<script language=javascript>alert('There was an error saving the file to disk!');</"+"script>"
return
 End Try
     else
 Span1.InnerHtml = "<script language=javascript>alert('File upload ERROR,because the file exist!if you replace it,please select replace');</"+"script>"
 end if else
Try
File1.PostedFile.SaveAs(filepath)
Span1.InnerHtml = "<script language=javascript>alert('File successfully written to disk!');</"+"script>"
return
 Catch Exc As Exception
Span1.InnerHtml = "<script language=javascript>alert('There was an error saving the file to disk!');</"+"script>"
return
 End Try
 end if          End If
end ifEnd Sub
</script>
</head>
<body>
<form  enctype="multipart/form-data" name="fileup" id="fileup" runat="server">
  <table width="100%" border="1" cellspacing="1" cellpadding="1">
    <tr> 
      <td width="10%" bgcolor="#E5E5E5">File:</td>
      <td width="39%"><input id="File1" name="File1" type=file runat="server" > </td>
      <td width="39%">If file exist,replace it? 
        <input name="replace" id="replace" type="checkbox" value="" runat="server"> 
      </td>    
  </table>
  <br>
<input type=button id="Button1" value="Upload" OnServerClick="Button1_Click" runat="server">
<input type="button" name="Button" value="Cancel" onClick="javascript:window.close();">
</form><span id=Span1 runat="server" /><span id=Span2 runat="server" />
</body>
</html>