Location of user files with a ClickOnce application

落爺英雄遲暮 提交于 2019-12-07 08:14:13

问题


I have a WinForms app that I am trying to deploy with ClickOnce. It consists of an executable and a dependent dll, plus a bunch of loose xml files in a folder called "Map". The xml files all seem to be present and correct in the generated clickonce package and are all included in the .manifest file.

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

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

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

What am I doing wrong? Is this the correct way to be bundling extra files with my application? I would actually like the Maps folder to be somewhere the user can easily access and add their own files to anyway.


回答1:


ok, I eventually found a code snippet that helped me out. The xml files were already being put into the ClickOnce "data directory" (this can be configured using the "application files" button on the publish tab of the project settings dialog. Then you can get at the data directory as follows:

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


来源:https://stackoverflow.com/questions/4188681/location-of-user-files-with-a-clickonce-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!