1
votes

I have a WPF app (installed on Windows 10 machines) that relies on XML files for various data elements.

After building the app and installing it, the app and XML files are deployed to different folders, as follows:

XML Files
[AppData\Local\Apps...]\vita..tion_4af4e5dd3b243aa8_0001.0000_fa5707b5107abce1

EXE
[AppData\Local\Apps...]\vita..tion_4af4e5dd3b243aa8_0001.0000_f75ca9501de16621

This prevents me from accessing my files using something like this:

    Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\XML\\GeneralInfo.xml";

Questions

  • How can I refer to the XML files in code?
  • Is this some weird artifact of a messed-up publishing?

Thanks!

EDIT

Using Publish Wizard (or Publish Now) to publish the app.

The XML files are marked as Build Action: "Content" and Copy to Output Directory: "Copy Always" in properties.

1
Are you using Publish Wizard to create a ClickOnce application? How are you deploying your XML files? - appa yip yip
@appayipyip -- Just updated the question; thanks. - DPH

1 Answers

1
votes

I believe this is normal behavior not a result of some weird artifact of a messed-up publishing¹.

Try access your files using this:

var deployment = ApplicationDeployment.CurrentDeployment;

var pathToXml = Path.Combine(deployment.DataDirectory, "MyFile.xml");

You will have to add a reference to System.Deployment on your application.

Hope that helps :)

-

¹ From an answer by Chester Hong on this question:

Each ClickOnce application is installed in per-user, per-application cache folder. You can find the folder like:

C:\Users\username\AppData\Local\Apps\2.0

You can go to Publish tab and click Application Files button. The files whose Publish Status are Data File will be installed into data folder, which you can specify by CurrentDeployment.DataDirectory property.

(Few parts ommited, adjusted and highlited by me)