Solved

image

Posted on 2011-09-16
2
365 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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