Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
**In browser view source:**
<img src="D:\VS 2013\BusinessClass2\BusinessClass2\Img\butterfly(Butterfly).jpg" />
but image is not showing at all.
**In Controller:** 
string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension  
string myfile = name + "(" + employee.Emp_name + ")" + ext; // append Employee name
var path = Path.Combine(Server.MapPath("~/Img"), myfile);


What I have tried:

**In View:**
<img src="@Html.Raw(item.Emp_image)"/>
**also tried:**
<img src="@Url.Content(item.Emp_image)"/>
Posted
Updated 3-Sep-16 11:29am

1 solution

If your image is not showing its because it does not exist. Make sure the file D:\VS 2013\BusinessClass2\BusinessClass2\Img\butterfly(Butterfly).jpg exists and that your web application has proper security rights to that file/directory.
 
Share this answer
 
Comments
tahirraza21 3-Sep-16 17:34pm    
An image with the same name is present in that particular folder.. is there any other way to save only ~\Img\pic.jpg rather than to save the whole root directory path
David_Wimbley 3-Sep-16 17:40pm    
When you say save only ~/Img/pic.jpg are you saying you are saving the file path in the DB?
tahirraza21 3-Sep-16 17:46pm    
Yes ofcourse .. let suppose i run this Solution to any other machine which didn't have "D:" drive ,u better know what would happen??
David_Wimbley 3-Sep-16 17:55pm    
You need to either host all files in a folder within your projects solution.

For example, you should have a folder labeled Content. Inside that folder, add another called Images. Then the directory you would save would be ~/Content/Images. In another column, you could store the file name and then concat those two columns to get the file path.

If you don't want to concat, then you would just store ~/Content/Images/<image>.png in that column. In your view you would then use <img src='@Url.Content("~/Content/Images/<image>.png")' /> to view that file.

Displaying the file in this manner will eliminate the need for a d:\ drive on systems computer this app gets deployed on.
tahirraza21 3-Sep-16 18:02pm    
Sounds good.I'll try this logic too. Can u plz clear one more thing what would b razor syntax then?
@Url.Content(item.image_path)?? Or (item.image_path+image_name)

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900