• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

image url

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
JCWEBHOST
Asked:
JCWEBHOST
1 Solution
 
ivan_vaguninCommented:
Hi! Do you want to display an image from client machine (before uploading), or image from server (after uploading)?
0
 
JCWEBHOSTAuthor Commented:
yes, i want the user to browse for an image and display in the image, like a preview.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ivan_vaguninCommented:
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
 
JCWEBHOSTAuthor Commented:
how do i set the local path?
0
 
ivan_vaguninCommented:
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
 
JCWEBHOSTAuthor Commented:
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
 
ivan_vaguninCommented:
Hi! Do you use AsyncFileUpload from ajax toolkit? Do you want to display preview after file is uploaded to server?
0
 
JCWEBHOSTAuthor Commented:
yes, i am using AsyncFileUpload.
0
 
ivan_vaguninCommented:
Do you save file some where on server (DB or FS), once it is uploaded?
0
 
JCWEBHOSTAuthor Commented:
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
 
Tom BeckCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now