Ok, so here’s a bit of code. I’m having an issue where I want to save to a pre-defined location, and I want to have a pre-defined name for a file. Neither FileStream nor StreamWriter allows you to set both of those paramters as far as I can tell, based on what I’ve seen on MSDN.
FileStream fs = new FileStream("PermaServerList", FileMode.Create, FileAccess.Write);
StreamWriter hiddensw = new StreamWriter(@"Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments", false);
So, if you look at that, how would I get it to save a file called “PermaServerList” to the location “My Documents”, regardless of the version of Windows they’re using? I don’t want to hard code in a location, I want it to always be whatever My Documents is in their particular version.
Alternatively, the idea behind this is that every time the program starts, I want it to load the list they last saved automatically. Is there a -simple- way to do this? Right now, the idea is that I’ll just save to their chosen location, and then make a second copy in my pre-defined location and just load that on program startup. Ideas?
That’s how you’d write to the file, for example. The
SpecialFolferenum will get you the location of the “My Documents” directory every time, regardless of what version of Windows they’re using, or whether the folder is mapped to a network location, etc.I’m not sure what you mean by “load the file when the program starts”; I assume your issue is that you need the directory location, beyond that it’s just a question of opening it as a stream and working with it.