Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

image

Hey guys, i have a file upload where i select an image, my problem is to load the selected image to an image control.

Please help?

here my code:

 
protected void AsyncFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        if (AsyncFileUpload.PostedFile != null && AsyncFileUpload.PostedFile.FileName != null)
        {
            Boolean fileOK = false;

            string fileExtension = System.IO.Path.GetExtension(this.AsyncFileUpload.PostedFile.FileName);
            String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };

            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileOK = true;
                }
            }

            if (fileOK == true)
            {
                byte[] myimage = new byte[AsyncFileUpload.PostedFile.ContentLength];
                HttpPostedFile Image = AsyncFileUpload.PostedFile;
                Image.InputStream.Read(myimage, 0, (int)AsyncFileUpload.PostedFile.ContentLength);
                Session.Add("image", myimage);

                string path = System.IO.Path.GetFullPath(this.AsyncFileUpload.PostedFile.FileName);
                imgLoading.ImageUrl = path;
            }
            else
            {
                Session.Remove("image");
                imgLoading.ImageUrl = "~/images/no-image-available.jpg";
                return;
            }
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial