ClickOnce应用程序中用户文件的位置 [英] Location of user files with a ClickOnce application

查看:148
本文介绍了ClickOnce应用程序中用户文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,正在尝试通过ClickOnce进行部署。它包含一个可执行文件和一个相关的dll,以及一个名为 Map的文件夹中的一堆松散的xml文件。 xml文件似乎在生成的clickonce软件包中都存在并且正确,并且都包含在.manifest文件中。

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"))

当我查看 appPath(这是 C:\Users\Mark\AppData\Local\Apps\2.0\0H6ZLXXN.30V\3TNO49OJ.8JH\midi ..tion_5194807c0e95e913_0000.0004_b9d52c73fd4d58ad\ ),有应用可执行文件和dll,但Maps文件夹不存在。

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.

我是什么做错了吗?这是与我的应用程序捆绑额外文件的正确方法吗?实际上,我实际上希望Maps文件夹位于用户可以轻松访问并添加自己的文件的位置。

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.

推荐答案

好,最终,我找到了一个帮助我解决问题的代码段。 xml文件已经放入ClickOnce数据目录中(可以使用项目设置对话框的发布选项卡上的应用程序文件按钮进行配置。然后,您可以按如下所示进入数据目录:

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;
        }
    }

这篇关于ClickOnce应用程序中用户文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆