Dim hfc As HttpFileCollection = Request.Files Dim imagePath As String = FileUpload2.PostedFile.FileName Dim imagesize As String Dim imagename As String = Path.GetFileName(imagePath) Dim ext As String Dim contenttype As String = String.Empty Try For i As Integer = 0 To hfc.Count - 1 Dim hpf As HttpPostedFile = hfc(i) ext = Path.GetExtension(hpf.FileName) imagesize = hpf.ContentLength If hpf.ContentLength > 0 Then 'Set the contenttype based on File Extension Select Case ext Case ".jpg" contenttype = "jpeg" Exit Select Case ".jpeg" contenttype = "jpeg" Exit Select Case ".png" contenttype = "png" Exit Select End Select If contenttype <> String.Empty Then Dim fs As Stream = hpf.InputStream Dim br As New BinaryReader(fs) Dim bytes As Byte() = br.ReadBytes(fs.Length) ViewState("imageName") = hpf.FileName ViewState("imageType") = contenttype ViewState("imageContent") = bytes ViewState("imageLength") = imagesize insertData() Else lblMsg.ForeColor = System.Drawing.Color.Red lblMsg.Text = "Photo extension " & ext & " is not accepted." End If End If Next i
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)