0

I created a wpf application that can create, write to, and read from a .txt document to store and persist data. Currently the application creates the text file within the solution folder, but what I would like to accomplish is the ability of the executable file to act as a stand-alone application that can spawn the text file somewhere on the user's computer, and continually persist and retrieve data from that file.

So, theoretically I could send a copy of the executable to a friend, they could open it and upon saving data a file would be spawned on their computer which would then be called whenever the application was run.

Right now what I had in mind for an answer is which folder I would need to use in this call within my application:

FileStream fs = new FileStream("ListOfTasks.txt", FileMode.OpenOrCreate);
StreamReader s = new StreamReader(fs);

Or otherwise, what other methods I could use to cause my executable to act as a stand-alone that can persist data without a database.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mcraenich
  • 745
  • 1
  • 14
  • 38

1 Answers1

0

You don't want to be writing to the solution folder, since that will require administrative privileges on any Vista+ machine.

You might want to look into using the ProgramData folder, see this question for more information: Write in "ProgramData" folder (W7 and Vista) .NET

This is an excellent resource for working out where you should be writing files, based on a few different scenarios:

Where should I put program data: http://blogs.msdn.com/b/cjacks/archive/2008/02/05/where-should-i-write-program-data-instead-of-program-files.aspx

Community
  • 1
  • 1
KingCronus
  • 4,509
  • 1
  • 24
  • 49
  • Thanks. I used that link and my app was able to spawn the file in the MyDocuments folder, however it is running into issues when I try to write to the file. I am going to continue to work on it and look for solutions. – mcraenich Jun 14 '13 at 13:46
  • Turns out I have an unhandled exception. The file that is being read and written to isn't being closed before I access it again. – mcraenich Jun 14 '13 at 13:49