c# - How is my app finding an old version of an ancillary text file? -
i have code reads encrypted credentials text file. updated text file include connection string. else read , decrypted fine, not connection string (naturally, updated code accordingly, too).
so got wondering: reading correct file. answer: no! file in \bin\debug dated 6/5/2012 9:41 am, code:
using (streamreader reader = file.opentext("credentials.txt")) { string line = null; messagebox.show(file.getcreationtime("credentials.txt").tostring()); ...shows 6/4/2012 2:00:44 pm
so searched hard drive instances of "credentials.txt" see reading file from. found 1 instance, 1 today's date in \bin\debug.
???
note: credentials.txt not part of solution; should be? (iow, copied \bin\debug, didn't perform "add | existing item")
provided don't change current directory, file in bin\debug going 1 being read, you're not specifying full path.
the problem due differences between different file dates. creation date (which fetching , displaying 6/4 @ 2:00:44pm) different date modified (which shown default in windows explorer). date can fetched using file.getlastwritetime instead of getcreationtime.
that being said, recommend using full path file, , not assuming current directory same executable path. specifying full path (which can determined based on executable path) safer, , less cause problems later. can done via:
var exepath = system.io.path.getdirectoryname(system.reflection.assembly.getentryassembly().location); var file = system.io.path.combine(exepath, "credentials.txt"); using (streamreader reader = file.opentext(file)) { // ...
Comments
Post a Comment