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 8735269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:01:02+00:00 2026-06-13T10:01:02+00:00

Possible Duplicate: Getting path relative to the current working directory? I have code in

  • 0

Possible Duplicate:
Getting path relative to the current working directory?

I have code in C# that includes some images from an absolute path to a relative so the image can be found no matter where the application fold is located.

For example the path in my code (and in my laptop for the image) is

C:/something/res/images/image1.jpeg

and I want the path in my code to be

..../images/image1.jpeg 

So it can run wherever the folder is put, whatever the name of the C: partition is etc.

I want to have a path in my code which is independant of the application folder location or if it is in another partition, as long as it is in the same folder as the the rest of the solution.

I have this code:

 try 
 { 
     File.Delete("C:/JPD/SCRAT/Desktop/Project/Resources/images/image1.jpeg");
 } 
 catch (Exception) 
 { 
      MessageBox.Show("File not found:C:/Users/JPD/Desktop/Project/images/image1.jpeg");
  } 

This code only runs if the file and folder are in that certain path, (which is also the location of the code) I wish for that path to be relative so wherever I put the whole folder (code, files etc) the program will still work as long as the code (which is under project folder) is at the same location with the folder images… what should I do?

  • 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-06-13T10:01:02+00:00Added an answer on June 13, 2026 at 10:01 am

    Relative paths are based from the binary file from which your application is running. By default, your binary files will be outputted in the [directory of your .csproj]/bin/debug. So let’s say you wanted to create your images folder at the same level as your .csproj. Then you could access your images using the relative path “../../images/someImage.jpg”.

    To get a better feel for this, try out the following as a test:

    1) create a new visual studio sample project,

    2) create an images folder at the same level as the .csproj

    3) put some files in the images folder

    4) put this sample code in your main method –

        static void Main(string[] args)
        {
            Console.WriteLine(Directory.GetCurrentDirectory());
            foreach (string s in Directory.EnumerateFiles("../../images/"))
            {
                Console.WriteLine(s); 
            }
            Console.ReadLine(); // Just to keep the console from disappearing.
        }
    

    You should see the relative paths of all the files you placed in step (3).

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

Sidebar

Related Questions

Possible Duplicate: Getting python.exe path at run time I have a python app that
Possible Duplicate: Getting current device language in iOS? I have an app which uses
Possible Duplicate: Getting a FILE* from a std::fstream I am working on Linux and
Possible Duplicate: Getting the application's directory from a WPF application I want to acess
Possible Duplicate: Getting Filename from file descriptor in C Obtain filename from file pointer
Possible Duplicate: Getting the ID of the element that fired an event using JQuery
Possible Duplicate: Getting a FILE* from a std::fstream Is there a way to obtain
Possible Duplicate: Getting the timestamp from last saturday (every week)? If today is Sunday,
Possible Duplicate: getting segmentation fault in a small c program Here's my code: char
Possible Duplicate: # in url getting ignored in php 5.2 I have following link

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.