c# - Application.StartupPath is changed after app is added to msconfig startup -
this question has answer here:
and thank taking time me.
i have app i'm adding startup in registry code:
registrykey setrunatstartup = registry.localmachine.opensubkey ("software\\microsoft\\windows\\currentversion\\run", true); setrunatstartup.setvalue("mls", application.executablepath.tostring()); and have ini.xml file needs in same folder app. access in manner:
xmldocument doc = new xmldocument(); doc.load(application.startuppath.tostring() + "/ini.xml"); the problem is, after rebooting computer application.startuppath no longer returning old path returns c:\windows\system32\myapp.exe, throws exception: cannot find needed ini.xml in folder. how can fix this? need method return real path in order access ini.xml. thank you!
don't use current working directory. instead use:
assembly.getexecutingassembly().location like so:
path.combine( path.getdirectoryname(assembly.getexecutingassembly().location), "myinifile.ini")
Comments
Post a Comment