0

this is the code to read the complete path with name of all files (images) from the folder inside the project

 @{ string[] imgfiles = Directory.GetFiles(@"D:\MVClearningProjects\Demo\Demo\Property_Data\Images\" + item.Property_ID, "*.*");}

this code is to load the first image to cshtml view file

 <img src="@Url.Content(imgfiles[0])" alt="carousel bootstrap first" readonly style="width:200px; height:120px;"  />
//not allowed local resources when I run this project  usig ISS
  • Welcome to StackOverflow. Please spend some time and visit [help center](http://stackoverflow.com/help) to get accustomed to the site. Also check [how to give examples](http://stackoverflow.com/help/mcve) and [how to ask](http://stackoverflow.com/help/how-to-ask) – Techie Feb 04 '16 at 17:35

2 Answers2

0

Like the error message is telling you, you are not allowed to do that. Due to security reasons, most browsers simply will not allow the use of file://. You need to host it with your application and load it from the web server.
Have a look at this great SO answer for an explanation and proposed solution to the problem.

Community
  • 1
  • 1
sjokkogutten
  • 2,005
  • 2
  • 21
  • 24
0

This error was due to using the .physical path instead of virtual in following code

@{ string[] imgfiles = Directory.GetFiles(@"D:\MVClearningProjects\Demo\Demo\Property_Data\Images\" + item.Property_ID, "*.*");}
 <img src="@Url.Content(imgfiles[0])" alt="carousel bootstrap first" readonly style="width:200px; height:120px;"  />

I fixed it by replacing the physical path with virtual

 @{ string[] imgfiles = Directory.GetFiles(@"D:\MVClearningProjects\Demo\Demo\Property_Data\Images\" + item.Property_ID, "*.*");
            for (int i = 0; i < imgfiles.Length; i++)
            {//converting physical address into virtual
                imgfiles[i]= imgfiles[i].Replace(@"D:\MVClearningProjects\Demo\Demo", "~").Replace(@"\", "/");
            }
        }
<img src="@Url.Content(imgfiles[0])" alt="carousel bootstrap first" readonly style="width:200px; height:120px;"  />