Solved

image url

Posted on 2011-09-16
12
261 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mail.To.Add 5 28
HttpPostedFile 1 26
ASP/VB email question 4 35
Calculate number of nights between two dates 5 28
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

832 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