Converting the hardcoded file path into relative URL

Turgunpulot

New member
Joined
May 18, 2022
Messages
3
Programming Experience
Beginner
static readonly string folderPath = @"C:\Users\SomeUser\source\repos\MyProject";
How can I convert this file path into relative url in c#, so that another person cloning this project into his pc can access the project without changing this file path?
 
Last edited:
Look at the Environment.GetFolderPath method to get various standard folder paths. You can then use Path.Combine to create a path for subfolders of these standard folders.

That said, what is this path for? I hope this is not your application trying to access the path of the project it was built from, because that would generally be a bad thing.
 
Look at the Environment.GetFolderPath method to get various standard folder paths. You can then use Path.Combine to create a path for subfolders of these standard folders.

That said, what is this path for? I hope this is not your application trying to access the path of the project it was built from, because that would generally be a bad thing.
I need to share this project with my friend. he needs to check it for errors. he commented: "use relative url so that I dont have to change the fiel path. when I clone it, i should be able to use the file path."
 
That doesn't answer my question. What is the path for? Why does the path need to be there at all? That your friend needs it to be valid is irrelevant if it shouldn't even be there in the first place. Please answer the question that you're actually asked.
 
No you don't. How does it make sense for an application to access data files from the project folder when that project folder only exists on a development machine? How could you possibly have a valid path to a project folder once you deploy the application to an end user?
 
Back
Top Bottom