Confusion over relative and absolute paths

I have a WPF program that processes images on a canvas.

I am at the point where I am trying to use serialization to be able to save the contents of my program and reload it at a later stage.

So, the moment I insert any images into the control, I use the absolute values ​​of the path, I understand that this would be a bad idea for a program in which I want to save the state of the program and restart it later.

So what is the best course of action in this situation.

Do I create a folder inside my WPF project, for example, "Images", and then copy all the images that I use in my program into this folder, and then specify the path to this?

Or am I completely on the wrong lines here?

+4
source share
2 answers

If you serialize the status data of your application, you usually create a folder in one or more of the so-called system special folders, which you can get by calling Environment.GetFolderPath .

For example, you can store data with the application area (the same for all users) in a folder under a special folder specified in the SpecialFolder.CommonApplicationData element (which is located in C:\ProgramData on Windows 7 systems).

Data that refers to the current roaming user (who is running on multiple computers on the network) will be stored in the folder below SpecialFolder.ApplicationData . There is also SpecialFolder.LocalApplicationData for a user without roaming.

You can view the list of Environment.SpecialFolder to get an overview.

+1
source

From your own experience, create a folder and save the images there. This will simplify your life in the long run, and it will make it easy to see where the application resources are.

0
source

Source: https://habr.com/ru/post/1493402/


All Articles