Location of user files with ClickOnce application

I have a WinForms application that I am trying to deploy using ClickOnce. It consists of an executable file and a dependent dll library, as well as a bunch of free XML files in the Map folder. All XML files appear to be present and correct in the created clickonce package and they are all included in the .manifest file.

However, when I install and run, using the following code gives me a directory exception not found:

string appPath = Path.GetDirectoryName(Application.ExecutablePath);
string mapPath = Path.Combine(appPath, "Maps");
foreach (string xmlFile in Directory.GetFiles(mapPath, "*.xml"))

when I look in the "appPath" (which is C:\Users\Mark\AppData\Local\Apps\2.0\0H6ZLXXN.30V\3TNO49OJ.8JH\midi..tion_5194807c0e95e913_0000.0004_b9d52c73fd4d58ad\), there is an application executable and dll, but the Maps folder is missing there.

What am I doing wrong? Is this the right way to link additional files with my application? I would really like the Maps folder to be somewhere where the user can easily access and add their own files anyway.

+3
source share
1 answer

ok, I eventually found a piece of code that helped me. The xml files have already been placed in the ClickOnce data directory (this can be configured using the "application files" button on the publication tab of the project settings dialog box. Then you can go to the data directory as follows:

    private string GetDataDirectory()
    {
        if (ApplicationDeployment.IsNetworkDeployed)
        {
            return ApplicationDeployment.CurrentDeployment.DataDirectory;
        }
        else
        {
            return Application.StartupPath;
        }
    }
+11
source

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


All Articles