Solved

image url

Posted on 2011-09-16
12
276 Views
Last Modified: 2012-08-13
Hey guys i am using a file upload to browse for an image and display it on a image controle, but it not working.

here my code:

this is my value path:

C:\Documents and Settings\Administrator\Desktop\ramcon.co.za\slide_1.jpg

here my c# code
 
string path = System.IO.Path.GetFullPath(this.AsyncFileUpload.PostedFile.FileName);
                imgLoading.ImageUrl = "~/images/facebook.png";

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
12 Comments
 
LVL 8

Expert Comment

by:vsudip
ID: 36548309
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36548354
Hi! Do you want to display an image from client machine (before uploading), or image from server (after uploading)?
0
 

Author Comment

by:JCWEBHOST
ID: 36548365
yes, i want the user to browse for an image and display in the image, like a preview.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36548410
ok, then you need to set Url to local path, while System.IO.Path.GetFullPath(this.AsyncFileUpload.PostedFile.FileName) will give you path on server, which is not the same
0
 

Author Comment

by:JCWEBHOST
ID: 36548415
how do i set the local path?
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36548439
Hi You cannot do that in server code for security reasons, the only chance is to use javascript. Look following sample: http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/114822
0
 

Author Comment

by:JCWEBHOST
ID: 36548452
i have this javascript on my fileupload:

 
function uploadComplete(sender, args) 
{ 
    try 
    { 
        var fileExtension=args.get_fileName();
        var gif =fileExtension.indexOf('.gif');
        var png =fileExtension.indexOf('.png');
        var jpg = fileExtension.indexOf('.jpg');
        var jpeg = fileExtension.indexOf('.jpeg');
        
        if(gif > 0 || png > 0 || jpg > 0 || jpeg > 0) 
        { 
            $get("dvFileInfo").style.display='block'; 
            $get("dvFileErrorInfo").style.display='none'; 
            $get("<%=lblSuccess.ClientID%>").innerHTML = "File Uploaded Successfully"; 
        } 
        else 
        { 
            $get("dvFileErrorInfo").style.display='block'; 
            $get("<%=lblError.ClientID%>").innerHTML = "Allowed File extension are {.gif,.png,.jpg,.jpeg} supported"; 
            $get("dvFileInfo").style.display='none'; 
            return; 
        } 
    } 
    catch(e) 
    { 
        alert(e.message); 
    }      
}

Open in new window


please help
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36548515
Hi! Do you use AsyncFileUpload from ajax toolkit? Do you want to display preview after file is uploaded to server?
0
 

Author Comment

by:JCWEBHOST
ID: 36548530
yes, i am using AsyncFileUpload.
0
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36548552
Do you save file some where on server (DB or FS), once it is uploaded?
0
 

Author Comment

by:JCWEBHOST
ID: 36548574
i have a fileupload to browse for an image and and have a button to save to a database, but i want to have a preview befor hitting the save button.
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 36550332
This question is a duplicate of this one:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27311642.html?cid=1576

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) + "images\\";

Save your uploaded image to it:

myImage.Save(APP_PATH + "facebook.png");

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

imgLoading.ImageUrl = "~/images/facebook.png";
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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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