Here is a little piece of code which upload a file on web server in a particular folder.
'In the ASPX Form
<form id="frmName" method="post" encType="multipart/form-data" runat="server">
<INPUT type="file" name="txtImgFile">
'In Code Behind
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim vSaveFilePath As String = Nothing
Dim vImageFile As String = Nothing
Dim vFileName As HttpPostedFile
Dim vFileType As String
Dim vSplit() As String
Dim i As Integer = 0
Dim vFileSize As Integer
'- Upload Image Image
vSaveFilePath = Request.PhysicalApplicationPath
For i = 0 To Request.Files.Count - 1
vFileName = Request.Files(i)
If vFileName.FileName <> "" Then
vImageFile = vFileName.FileName
vFileSize = vFileName.ContentLength
vFileType = vFileName.ContentType
If System.IO.Path.GetExtension(vImageFile) <> ".jpg" Then
'Show Here Image Type Error Window
Exit Sub
End If
If CStr(vFileSize) > 81920 Then
'80KB = 81920 Bytes
'Show Here Size Error Window
Exit Sub
End If
vSplit = Split(vImageFile, "\")
vImageFile = vSplit(UBound(vSplit))
vSplit = Split(vImageFile, ".")
vImageFile = Me.txtCatName.Text.Trim & "-" & i + 1 & "." & vSplit(1)
vFileName.SaveAs(vSaveFilePath & "Images\Category\" & vImageFile)
End If
Next
Priyesh
priyeshdeshpande@yahoo.com