Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

image

Posted on 2011-09-16
2
Medium Priority
?
369 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 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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