Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

image url

Posted on 2011-09-16
12
Medium Priority
?
282 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
Independent Software Vendors: 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 2000 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

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!

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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.
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…

636 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