views:

50

answers:

3

I have a .NET CF project. In the project directory I put a simple xml file (users.xml) which has to be read by the device. When I debug the application on device emulator and try to load the file from code, the Exception is thrown (FileNotFoundException "Could not find file '\\users.xml'.").

Is there a mechanism to automatically deploy also configuration files to a device emulator?

A: 

You can try adding the file to your application, setting "Build Action" to content, and enabling "Copy to Output Directory". Also, I believe there's an option in emulator preferences which enables sharing files between emulator and the host OS.

Sphynx
The "Build Action" set to content and "copy to out dir" does not work. I can see in "Output window" that the files are deployed but when I try to load the file, FileNotFoundException is thrown.
dominolog
+1  A: 

Here is how to do it in VS2005. It deploys the file along with the project.
This is for a native application - it should be similar for a managed one.

Content field specifies whether to deploy the file to the target. The file is deployed to the same directory as the application. I am not sure how VS2005 handles the deployment in case you updated the file, meaning you might need to manually delete it on the device.

VS2005

Shaihi
+2  A: 

You have you path set wrong in your code. After following the instruction of Shaihi or Sphynx to get Studio to deploy the file, the file is then in the folder with the application.

Based on the fact that you're getting an error that it cannot find "\users.xml" tells me that you're either telling it to specifically look in the root folder or you haven't specified a folder.

Windows CE requires that you provide a fully-qualified path, so your application should either use the full path it is deployed to (i.e. "\Program Files\MyApp\users.xml") or you need to construct the path:

Path.Combine(
  Path.GetDirectoryName(
   Assembly.GetExecutingAssembly().GetName().CodeBase
  ), "users.xml");
ctacke
Path.Combine(...) gives in my case the '\\MyExe.exe\\users.xml' and the System.IO.DirectoryNotFoundException is thrown. What is wrong?
dominolog
bah, that's what I get for not checking my code - I've updated it in the answer
ctacke