Solved

image

Posted on 2011-09-16
2
356 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
2 Comments
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 250 total points
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now