2

On button click event i have coded like this to view image directly from file control.

protected void btnupload_Click(object sender, EventArgs e)
    {
        try
        {


            if (photoupload.HasFile)
            {

                imageuploaded.ImageUrl = "~/./" + string.Format( photoupload.PostedFile.FileName);
                if (imageuploaded.ImageUrl != null)
                    lblerror.Text = "File is Uploaded";
            }
            else
            {
                lblmsg.Text = "Please check all the fields";
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}

and the imageurl obtained from this coding is

http://localhost:4269/IMAG0990.jpg

where IMAG990.jpg is my image name but image is visible in image control , may be because this url is incorrect what should i do to view photo directly in image control without saving it to any folder.

VJain
  • 1,027
  • 7
  • 17
  • 37
  • the problem isn't url,it's because file dosen't saved.(u don't write any code for save) – reza jafari Nov 17 '13 at 04:16
  • but sir it will store, i want to upload the photo only if user is satisfied, i mean when it choose any pic then before saving it to the any folder or database ,it may be able to view it first so that irrelevant data won't store in database – VJain Nov 17 '13 at 05:26
  • 1
    for every browser go to this site: http://weblogs.asp.net/charithgunasekara/archive/2010/10/08/how-to-show-the-selected-image-file-without-saving-file-in-the-disk-before-upload.aspx – reza jafari Nov 17 '13 at 06:19

1 Answers1

1

test this code,it's work on IE for show image without save

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<script type="text/javascript">
    function setImage() {
        a1 = 'file://localhost/' + document.getElementById('file').value;
        a1 = a1.toLowerCase();
        if (a1.substring(0, a1.lastIndexOf('.png')) || a1.substring(0, a1.lastIndexOf('.jpg')) || a1.substring(0, a1.lastIndexOf('.jpeg')) || a1.substring(0, a1.lastIndexOf('.gif'))) {
            var img = document.createElement('img');
            img.setAttribute('src', a1);
            document.getElementById('prevImage').appendChild(img);
        } 
    }
</script>

</head>

<body>

<input type="file" id="file" />
<input type="button" value="preview" onclick="setImage();" />
<div id="prevImage"></div>

</body>

</html>
reza jafari
  • 1,228
  • 13
  • 14
  • past this code in notepad and change the format to .aspx.openwith IE.after browse and select image,click preview,and it's work.it's my test: http://tinypic.com/view.php?pic=mmzfxi&s=5 – reza jafari Nov 17 '13 at 13:32