0

I'm writing a program in C# for a pocket pc that uses Compact Framework 1.0 I need to read in data from a text file but Im not sure where to place the file since the program doesnt seem to be able to locate the file. I placed it root of the project folder and the code that tries to read is: StreamReader streamReader = new StreamReader("products.txt");

I need this to be working in a couple of days so I would be really thankful for all help.

ctacke
  • 66,480
  • 18
  • 94
  • 155

1 Answers1

0

This is likely be because when you develop in a Visual Studio environment, your application path will look like:

ProjectName\bin\Release\application.exe

When you deploy, your application path will look like this:

ProjectName\application.exe

The best way I have found around these issues is to NEVER place support files in the same directory as your executable.

string apps = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string docs = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

This will require more "record keeping" on your part, but your files should always be there.

  • 1
    I just query the path at runtime with `Path.GetDirectory(Assembly.GetExecutingAssembly.GetName.CodeBase)` – ctacke Aug 23 '12 at 14:18
  • OK, I concede to your method. That's why you've got 41k and I'm sitting at 3k. ;) –  Aug 23 '12 at 18:35