Click here to Skip to main content
12,405,303 members (63,631 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
hi friends

i have database in which 3 fields ID , ImageName, ImagePath
datatype for ImageName and ImagePath is Nvarchar

i have created a global variable :-
private Image _ProductImage;
 public Image ProductImage
    {
        get { return _ProductImage; }
        set { _ProductImage = value; }
 

    }
which returns image datatype

i have a imagecontrol in my aspx
in that image control i have to display image from database where in database only the path is defined in string
Products prod = new Products();
prod.ProductImage = sdr["ImagePath"];
ImageItem.ImageUrl = Server.MapPath(prod.ProductImage);
some wrong in this code please figure it out friends.... URGENT
Posted 14-Nov-12 0:36am
Updated 14-Nov-12 0:50am
member6016.1K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi
Can you try without using Server.MapPath ? Using '~' in the beginning.

ImageItem.ImageUrl = "~/IMAGES/Test.ico";


Regards
Dominic
  Permalink  
Comments
sreerajsn123 14-Nov-12 7:12am
   
actually i need to get varying images not a particular image
dominicthoppil 14-Nov-12 7:26am
   
Is the location of the image is outside your website?
You can refer the link
http://forums.asp.net/t/1608488.aspx/1
sreerajsn123 14-Nov-12 7:33am
   
no the images are in the same root ... in one folder named "images"
dominicthoppil 14-Nov-12 7:39am
   
if possible can you list some results (paths) assigning to
prod.ProductImage property when you are debugging.
sreerajsn123 14-Nov-12 7:43am
   
if i change the return value to string i will get the path value.. "G:\root\Images\634456168350187500s.JPG" but i need to convert this path to an image or i should get the image from folder using this path
sreerajsn123 14-Nov-12 7:58am
   
friend i got it..... i will share with you...

i changed private Image _ProductImage;
public Image ProductImage
{
get { return _ProductImage; }
set { _ProductImage = value; }


}
private string_ProductImage;
public string ProductImage
{
get { return _ProductImage; }
set { _ProductImage = value; }


}

and created a

private void showimage(string imagepath)
{
imagecontrol.ImageUrl = "~/foldername/" + imagepath +"";
}

and called this
prod.ProductImage = sdr["PImagePath"].ToString();
showimage(prod.productImage);
sreerajsn123 14-Nov-12 8:13am
   
thankyu dominicthoppil for your help
dominicthoppil 14-Nov-12 8:24am
   
very good :-)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

friend i got it..... i will share with you...

i changed
private Image _ProductImage; 
public Image ProductImage 
{ 
  get { return _ProductImage; } 
  set { _ProductImage = value; } 
}
to
private string_ProductImage; 
public string ProductImage 
{
 get { return _ProductImage; } 
 set { _ProductImage = value; } 
} 
and created a
private void showimage(string imagepath) 
{
 imagecontrol.ImageUrl = "~/foldername/" + imagepath +""; 
}
and called this

prod.ProductImage = sdr["PImagePath"].ToString(); showimage(prod.productImage);

[edit]code block added[/edit]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100