How to get folder path for ClickOnce application

前端 未结 7 1727
Happy的楠姐
Happy的楠姐 2020-11-29 16:45

I need to write a file in the same folder where a console ClickOnce .application (executable file) resides. The folder where it launches from.

I tried u

7条回答
  •  青春惊慌失措
    2020-11-29 17:20

    ApplicationDeployment.CurrentDeployment.ActivationUri might work

    "A zero-length string if the TrustUrlParameters property in the deployment manifest is false, or if the user has supplied a UNC to open the deployment or has opened it locally. Otherwise, the return value is the full URL used to launch the application, including any parameters."


    BUT what I think you really want is ApplicationDeployment.CurrentDeployment.DataDirectory which gives you a folder you can write data to. When you update the application anyways you'll lose what was in the original .exe folder, but you can migrate the data directory over to a new version of the app. Your app can write to this folder with whatever log files it has - and I'm pretty sure its guaranteed to be writable.

提交回复
热议问题