Solved

image

Posted on 2011-09-16
2
362 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Wayne Barron earned 250 total points
ID: 36548078
This is what I use
http://cffcs.com/Main.asp?Entry=22

There is 2 demonstrations:
C# and VB.NET
I use the VB.NET for my projects.

It is very sweet and easy to understand.
I will be uploading another example of this project with a database attached to it, just have not had the extra time.

Good Luck
Carrzkiss
0
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 250 total points
ID: 36550218
You would need to save the image to a directory that the web application has permission to read from then assign the saved image path to the source attribute of the Image control.

Example: You have a folder inside your web application that you save your uploaded images to called UploadedImages. The folder has read/write privileges for IIS_IUSRS. Get the path to that folder:

string APP_PATH = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath) + "UploadedImages\\";

Save your uploaded image to it:

myImage.Save(APP_PATH + "imageName.jpg");

Assign the image path to the source attribute of the Image control:

this.dynImage.Src = "UploadedImages/imageName.jpg";
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pressing download button in c# 7 34
Data organization issue 7 36
How to fix 'event logs could not be searched' error asp.net? 3 13
c#, case, if 4 17
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question