1

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?

Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59

2 Answers2

1

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.

Community
  • 1
  • 1
Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59
0

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.

amit dayama
  • 3,246
  • 2
  • 17
  • 28
  • I actualy have full rights to that location, when I use the full path the file is found with out any problume, but I need a solution that will work on any PC the app will be installed into – Ravid Goldenberg Oct 28 '15 at 08:37
  • 2
    Are you looking for: string xmlStr = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Content/StationConfig.xml"); – amit dayama Oct 28 '15 at 08:41
  • Seems about right, and maybe this is the solution, can you refer me to a link that specify what every location represents? – Ravid Goldenberg Oct 28 '15 at 08:44
  • AppDomain.CurrentDomain.BaseDirectory >> refers to the current application direction, while when you were usiing ../ that refers to the working directory. There is a difference if you notice. Sorry i don't have links but you may search in google .. you will find many links related to it. – amit dayama Oct 28 '15 at 08:48
  • That almost solved it, problem is it is looking for the file at the folder that has all the .dll files while the actual folder holding the file is located elsewhere, the Content folder is located in the same folder in which the wpf.exe.config was created on installation. How do I refer to that location? – Ravid Goldenberg Oct 28 '15 at 09:45
  • can you tell me where it's currently looking at and where do you want to save the file – amit dayama Oct 28 '15 at 09:46
  • and where do u want it to save – amit dayama Oct 28 '15 at 09:51
  • The file was saved to : C:\Users\petric\AppData\Local\Apps\2.0\X0NQ558A.39P\6MP3V3G7.G9P\mo.p...exe_0000000000000000_0001.0000_none_c100fcdedb524454\Content But the programm searches it at : C:\Users\petric\AppData\Local\Apps\2.0\X0NQ558A.39P\6MP3V3G7.G9P\mo.p..tion_0000000000000000_0001.0000_286e1a4dca9b4588 s – Ravid Goldenberg Oct 28 '15 at 10:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93578/discussion-between-amit-dayama-and-petric). – amit dayama Oct 28 '15 at 10:11