How do you display a list of images, from a folder on hard drive, on ASP.NET website?

后端 未结 3 883
粉色の甜心
粉色の甜心 2020-12-08 22:42

I am trying to make a simple photo gallery website. Using ASP.NET and C#. Right now I don\'t have a server set up but I am just using the development one that Visual Studio

3条回答
  •  鱼传尺愫
    2020-12-08 23:07

    You're creating an element with a URL of C:\Users\Jordan\Desktop\Web Images\SomeImage.jpg. Obviously, that won't work in a web browser.

    You should copy the images to a subfolder of your project, and set the URL to a relative URL, like this:

    img.ImageUrl = "~/Web Images/" + Path.GetFileName(s);
    

    (Assuming that the Web Images folder is a subfolder of the application root)

提交回复
热议问题