上传后如何清除文件?

时间:2013-03-05 16:08:17

标签: asp.net vb.net file-upload

我正在使用visual developer 2012,并有一个简单的表单将文件上传到服务器,然后在另一个表中输入文件的名称。无论出于何种原因,它会运行两次并在第二个表中输入两次值:

Protected Sub BtnUploadImg_Click(sender As Object, e As EventArgs) Handles BtnUploadImg.Click
    If IsPostBack Then
        ' Dim CurrentPath As String = Server.MapPath("C:\DSimages\")
        If FileUpLoad1.HasFile = True Then
            Try
                FileUpLoad1.SaveAs("C:\DSimages\" & _
                   FileUpLoad1.FileName)
                Label1.Text = "File name: " & _
                   FileUpLoad1.PostedFile.FileName & "<br>" & _
                   "File Size: " & _
                   FileUpLoad1.PostedFile.ContentLength & " kb<br>" & _
                   "Content type: " & _
                   FileUpLoad1.PostedFile.ContentType
                ImageDataSource.InsertParameters("ImgName").DefaultValue = FileUpLoad1.PostedFile.FileName
            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
            End Try
        Else
            Label1.Text = "You have not specified a file."
        End If
    End If

    ImageDataSource.Insert()
    FileUpLoad1.PostedFile.InputStream.Dispose()     

End Sub


1 个答案:

答案 0 :(得分:0)

页面加载事件下是否有相同的代码?回发将触发两个事件,所以如果你这样做将会运行两次。