Solved

image url

Posted on 2011-09-16
12
231 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
Comment Utility
0
 
LVL 18

Expert Comment

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

Author Comment

by:JCWEBHOST
Comment Utility
yes, i want the user to browse for an image and display in the image, like a preview.
0
 
LVL 18

Expert Comment

by:ivan_vagunin
Comment Utility
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
Comment Utility
how do i set the local path?
0
 
LVL 18

Expert Comment

by:ivan_vagunin
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:JCWEBHOST
Comment Utility
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
Comment Utility
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
Comment Utility
yes, i am using AsyncFileUpload.
0
 
LVL 18

Expert Comment

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

Author Comment

by:JCWEBHOST
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

9 Experts available now in Live!

Get 1:1 Help Now