Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:15:55+00:00 2026-05-27T10:15:55+00:00

net/C# application I have list of items. In the code behind: I want to

  • 0

net/C# application I have list of items.

In the code behind:
I want to assign a picture from my local resources for each item. the items name and the picture names are the same.
The pictures are all in a “image” folder in my project.

Example of how I assign a picture to an item:

Item1.PictureUrl = "images/items/" + item1.Name + ".jpg";

I have items that don’t have pictures. I want to assign for them a default picture.

I tried to check if the picture exists using this:

foreach(ObjectItem item in ListOfItems)
{
    if(File.Exists("images/items/"+item.Name+".jpg"))
            item.PictureUrl = "images/items/"+item.Name+".jpg";
        else
            item.PictureUrl= "images/Default.jpp";
}

But the File.Exists method is always returning false, even if the picture exist.
I also tried to use ‘\’ instead of ‘/’ but didn’t work

How can I do it?

Thank you for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:15:56+00:00Added an answer on May 27, 2026 at 10:15 am

    You need to convert the relative file path into a physical file path in order for File.Exists to work correctly.

    You will want to use Server.MapPath to verify the existence of the file:

    if(File.Exists(Server.MapPath("/images/items/"+item.Name+".jpg")))
    

    Also, when you use Server.MapPath, you should usually specify the leading slash so that the request is relative to the web application’s directory.

    If you don’t provide the leading slash, then the path will be generated relative to the current page that is being processed and if this page is in a subdirectory, you will not get to your images folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My SSRS report fetches data from my DATAWAREHOUSE. The ASP.NET application I have is
I have an ASP.NET application where i have more than 100 pages.In each pages
I have a List<> of items which I want to display in a 3
I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic
I have asp.net MVC2 application. I am using VS2008 and want to hook up
I have created an asp.net application using Entity Framework. In this I want to
So I've taken over a VB.net web application project from another developer and have
I've created an ASP.NET MVC 2.0 application. I have a dropdownbox with a list
In my ASP.Net application I have a requirement that when a user clicks on
In my ASP.NET application I have a web.config file. In the web.config file I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.