In PageLoad Code Add ..
Page.Form.Attributes.Add("enctype", "multipart/form-data")
On webpage ....
<asp:updatepanel id="UpdatePanel6" runat="server">
<triggers> <asp:postbacktrigger controlid="btnFileUpload">
<contenttemplate>
<asp:fileupload id="FileUpload1" runat="server" width="99%" allowmultiple="True"> | <asp:button id="btnFileUpload" runat="server" text="Upload" font-size="x-small" width="75" onclick="btnFileUpload_Click">
|
In Code Have Upload Handler..
' ---------------------------------------------------------------------------
' UploadButton_Click
' ---------------------------------------------------------------------------
Protected Sub btnFileUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnFileUpload.Click
lblUpLoadErr.Text = ""
Try
If FileUpload1.HasFile Then
For Each fle As HttpPostedFile In FileUpload1.PostedFiles
If ExtCheck(fle.FileName) Then
Dim fileName As String = Path.GetFileName(fle.FileName)
Dim newPath As String = TreeView1.SelectedNode.Value
If Not Directory.Exists(newPath) Then
Directory.CreateDirectory(newPath)
End If
Dim newfullFilename As String = myDir + "\" + fileName
fle.SaveAs(newfullFilename)
Else
lblUpLoadErr.Text += "Illegal Filename,"
End If
Next
lblUpLoadErr.Text = String.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count)
LoadFiles()
End If
Catch ex As Exception
lblUpLoadErr.Text = "Error in uploading file." + ex.Message
End Try
End Sub
I have been using this in production for awhile... I also left myDir undefined as that is the path where to store the file..
Regards,