I've created a webform using asp.net, the purpose of the webform is to connect to a database, pull the selected information out of the database, and display it on the screen. It is also capable of adding and updating records in the database. One of the fields in the database is a Logo (which is obviously a picture).
I would like to, and have managed to, display this logo when a particular company's Scheme code is selected from a dropdown menu. I used some Javascript for this. Happy days!
I would also like to be able to select an image from the disk to preview on the web page, and then if it is OK, upload it to the database. I can preview it fine, I used some Javascript for this. But because I've used some Javascript front-end, I'm no longer using the familiar FileUpload
control.
I need to be able to convert the file which gets selected in the <input ID="logoPrvw" type ="file" onchange="previewFile()" runat="server" />
control into a byte array in order to place it in the database table
The Javascript on the front-end code, within the head tag is...
<script type="text/javascript">
function previewFile() {
var preview = document.querySelector('#<%=imgLogo.ClientID %>');
var file = document.querySelector('#<%=logoPrvw.ClientID %>').files[0];
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
}
if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "";
}
}
</script>
I'm looking into the HtmlInputFile class but I can't find anything useful.
Cheers again folks!