'Find 'Application Files' directory after publish by ClickOnce
After publish by using ClickOnce in C#, I got fully confused about how to find the directory of the folder: 'Application Files'. The reason I want to do this is I want to put some files into this folder and let C# to read them after the user installed my application.
I have tried like: System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
but I always got like: C:\Users\AppData\Local\Apps\2.0\4DAZ7HKJ.7TP\OZ02N2HD.7PG\cons..tion_a9321ce7eb14b63e_0001.0000_7ed45506b35ff771, which I don't want. Since my publish folder is in D:\, what I want is like: D:\Application Files.
Thanks in advance to anyone who read my question!

Solution 1:[1]
Following this path you do not want, you find an executable capable of respecting what you expect to have using
System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
Solution 2:[2]
For those looking for the WPF way, here two equivalent methods:
var appPath = System.AppDomain.CurrentDomain.BaseDirectory
var appPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
and then use it like this:
var path = System.IO.Path.Combine(appPath, "image.png");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Caio de Paula Silva |
| Solution 2 |
