Add the enctype="multipart/form-data" name-value attribute to the <form> tag as follows:
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
If Not MyFile.PostedFile Is Nothing And MyFile.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(MyFile.PostedFile.FileName)
Dim strSaveLocation As String = Server.MapPath("Upload") & "\" & fn
Dim index = fn.LastIndexOfAny(".")
Dim GetExtension = fn.Substring(index + 1)
If (UCase(GetExtension) = "TXT") Or (UCase(GetExtension) = "DOC") Then
MyFile.PostedFile.SaveAs(strSaveLocation)
lblMessage.Text = "File Has Been Uploaded Successfully."
Else
lblMessage.Text = "Incorrect File format."
End If
Else
lblMessage.Text = "please select a file to upload."
End If
End Sub
Call friends with PC-to-PC calling -- FREE Try it now!
No comments:
Post a Comment