I a function belows which is being used to preview an image but that involves saving the image locally in my drive. I am using this feature in an data entry form which means if the user discards the form, I have to delete the image which I feel is not efficient. How can I go about previewing the image and only save it locally if the user saves the form. Thanks.
Protected Sub save_btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Save.Click
If uifuVouTypeUploadfile.PostedFile IsNot Nothing Then
' Check file size (mustn’t be 0)
Dim myFile As HttpPostedFile = uifuVouTypeUploadfile.PostedFile
Dim nFileLen As Integer = myFile.ContentLength
If nFileLen = 0 Then
'rqfvVouImage.ErrorMessage = "No file was uploaded."
'rqfvVouImage.IsValid = False
Return
End If
' Check file extension (must be JPG)
If System.IO.Path.GetExtension(myFile.FileName).ToLower() <> ".jpg" AndAlso System.IO.Path.GetExtension(myFile.FileName).ToLower() <> ".gif" AndAlso System.IO.Path.GetExtension(myFile.FileName).ToLower() <> ".bmp" Then
'rqfvVouImage.ErrorMessage = "The file must have an extension of JPG or GIF"
'rqfvVouImage.IsValid = False
Return
Else
myFile.SaveAs(MapPath(System.IO.Path.GetFileName(myFile.FileName).ToLower().ToString()))
'Show the uploaded resized picture in the image control
uiimgVouImage.ImageUrl = System.IO.Path.GetFileName(myFile.FileName).ToLower().ToString()
End If
End If
End Sub
You may construct the
Bitmapobject of uploaded file and write it toResponsestream.Take a look at these posts: