Monday, 22 September 2014

How to Preview Uploaded Image before Upload To Server

Here i will explain how to preview the image file before uploaded to server. When we upload any image file to server or to any file location.It is not possible to find out the write selection you have choose which u want to upload to server. By this example we are able to preview the selected image file before upload and choose the correct selection which u want to upload.

Take Asp.net file upload control to browse the selected image file which you want to upload to server.By using of jquery file we are able to preview the image before upload to the server.
Download Code

Html Code:
<html>
<head>
<style type="text/css">
body
{
    font-family: Arial;
    font-size: 10pt;
}
#dvPreview
{
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);
    min-height: 400px;
    min-width: 400px;
    display: none;
}
    .auto-style1 {
        text-decoration: underline;
        font-size: medium;
    }
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
    $("#fileupload").change(function () {
        $("#dvPreview").html("");
        var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
        if (regex.test($(this).val().toLowerCase())) {
            if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) {
                $("#dvPreview").show();
                $("#dvPreview")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(this).val();
            }
            else {
                if (typeof (FileReader) != "undefined") {
                    $("#dvPreview").show();
                    $("#dvPreview").append("<img />");
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        $("#dvPreview img").attr("src", e.target.result);
                    }
                    reader.readAsDataURL($(this)[0].files[0]);
                } else {
                    alert("This browser does not support FileReader.");
                }
            }
        } else {
            alert("Please upload a valid image file.");
        }
    });
});
</script>
</head>
<body>
<div>
    Browse Picture to view thw live image<br />
    <br />
<input id="fileupload" type="file" />
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>
    <span class="auto-style1"><em>Preview</em></span>
<br />
<br />
<div id="dvPreview">
</div>
</div>
</body>
</html>

Related Posts:

  • Freeze GridView Header Row In Asp.Net In Grid View Control You Can easily display all the collection of data and we can easily add sorting and paging, and perform in-line editing.Some time there is large no of data which makes grid view scro… Read More
  • How To Bounce Left a div by Using jQuery plugin And use in Asp.Net. Here i will explain how to move or bounce a particular division by using jquery. Here i will use .velocity() function instead of $.animate() animation engine. Velocity is a  animation engine that re… Read More
  • 3 Tire Architecture. 3-Tier architecture is a very well know buzz word in the world of software development whether it web based or desktop based. In this article I am going to show how to design a web application based on 3-tier architecture… Read More
  • How to Create Dynamic TextBox And Get Its Value Before i was explain How to create dynamic Asp controls.How to Generate Dynamic Asp ControlsNow Here i will show to you how to retrieving the value of the dynamically created Text Box In Asp.Net.  using Syst… Read More
  • Online Examination Here I Will Explain How to create a simple Online Examination Form by using c# in Asp.Net protected void Button1_Click(object sender, EventArgs e)     {         HttpC… Read More

0 comments::

Post a Comment

Copyright © 2025 DotNet-Ashok