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!
To include a file to your publish, you don't need to include it in the folder manually, instead you should add the file to your project and set its Build Action
to Content
. To make sure the file is included in publish, go to Project → Properties → Publish Tab → Application Files Button
and see if Publish Status
of your file is Include (Auto)
.
After deploying the application those files will be deployed near the application executable file. For example if you include image.png
, then you can find it this way:
var path = System.IO.Path.Combine(Application.StartupPath, "image.png");
Also if for any reason you are looking for your publish folder you can see the path you used for publish, in Project → Properties → Publish → Publish Location
or in <PublishUrl>
tag in your project file.
Regardless of the location you published the files, there is a copy of them in the \bin\debug
folder of your project under app.publish
folder.
按照您不想要的路径,您会发现一个可执行文件能够尊重您使用System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
所期望的内容
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.