Ravid Goldenberg
Ravid Goldenberg

Reputation: 2299

Wpf publish can't find content: "could not find part of the path "

I created a Wpf application, it's composed of 3 projects, in a project that is not my main project I'm accessing some config.xml file read data from and also write data to.

In my app I access this file simply as :

string xmlStr = File.ReadAllText("../Content/StationConfig.xml");

or:

doc.Save("../Content/StationConfig.xml");

It works fine on my app in debug mode, but when I publish I get the error:

could not find part of path

And the place it looks into is a on apps:

C:\Users\petric\AppData\Local\Apps\2.0\075BBVBO.9MZ\BWMQ2V0B.PE5\Content\StationConfig.xml

This file needs to be available on each PC my app will be installed into. My file build action is set to Content and it's copy to output directory is set to Copy always.

I have read a bunch of questions about this problem and still can't figure out a solution, also read this : WPF Application Resource, Content, and Data Files

Any suggestions?

Upvotes: 1

Views: 2149

Answers (2)

Ravid Goldenberg
Ravid Goldenberg

Reputation: 2299

Ok, after reading this question : Including xml files when deploying WPF application and with the kind help of amit dayama the solution was to look at

ApplicationDeployment.CurrentDeployment.DataDirectory

rather then looking at

AppDomain.CurrentDomain.BaseDirectory

as this answer is correctly suggesting.

Upvotes: 1

amit dayama
amit dayama

Reputation: 3326

It is looking for the directory C:\Users\petric\AppData\Local\Apps\2.0\075BBVBO.9MZ\BWMQ2V0B.PE5 because it's your current directory and trying to save the doc while publishing and checking if you have the permission or not. Quite possible it 's not allowing you to save. So check if you have full rights on that location. Other way round, Try to change location to some other path than relative path (just for time being). That might show you the right direction.

Upvotes: 0

Related Questions