Walking
Walking

Reputation: 477

Could not find part of the path for a resources file in a ClickOnce WPF application

I published my click once application in a test environment and I'm getting a can not find part of the path exception in a part where I need to access a file.

Could not find a part of the path 'C:\Users\admin\AppData\Local\Apps\2.0\E65K03BT.792\Resources\file.pem'.

I'm specifying this path in code as follows:

..\\..\\Resources\\file.pem

And all works well when I run it from visual studio.

It only fails on the actual deployed application.

Upvotes: 2

Views: 2344

Answers (2)

ChrisF
ChrisF

Reputation: 137148

When you run the program from Visual Studio

 ..\\..\\Resources\\file.pem

will resolve to the correct location as the Resources folder is in the correct relative location. However, when you run the file in your test environment either that file hasn't been deployed to the same relative location or maybe even not included in the deployment script at all.

In the first instance make sure that the file is correctly marked as being required for deployment. Then make sure that it gets deployed to the same relative location as it is when you run the program from Visual Studio.

Upvotes: 5

Walking
Walking

Reputation: 477

I have changed the properties of the file to have a build action of "Content", set the copy to output direcetory option to "Copy Always" , and I'm navigating to the file with this path : AppDomain.CurrentDomain.BaseDirectory + "Resources\pk-APKAICMTEV4SDON7GDPQ.pem"

Everything works now.

Thank you

Edit: Now I'm having the same issue with an xml file that belongs in the a folder of the main project. Any ideas?

Upvotes: 0

Related Questions