vb.net - How to save File info over restart -
ok have application when click "browse" button if open file dialog, in dialog select dll , takes file sends listbox. (openfiledialog1 code:)
private sub openfiledialog1_fileok(sender object, e system.componentmodel.canceleventargs) handles openfiledialog1.fileok dim filename string = openfiledialog1.filename.substring(openfiledialog1.filename.lastindexof("\")) dim dllfilename string = filename.replace("\", "") listbox1.items.add(dllfilename) dlls.add(dllfilename, openfiledialog1.filename) dim filehistory string = dllfilename + "|" + openfiledialog1.filename strlist.add(filehistory) ''dim stringtosplit string() = openfiledialog1namedata.split("|") ''dim filenametoassign string = stringtosplit(0) ''dim pathtoassign string = stringtosplit(1) 'msgbox(filenametoassign) 'msgbox(pathtoassign) end sub
as can see i'm splitting info , idea create string/string collection every time dll chosen/added, have filename + path saved on restart can call re-populate listbox.
i've tried many methods , haven't had luck. able save name of dll. run problem of how can save "filenametoassign | pathtoassign" separate string each time , on mybase.load call them re-populate listbox via command:
dlls.add(dllfilename, openfiledialog1.filename)
(the dim of dlls)
dim dlls new dictionary(of string, string)
for saving textfile this:
dim sb new system.text.stringbuilder each k string in dlls.keys sb.appendline(k & "|" & dlls(k)) next io.file.writealltext(io.path.combine(application.startuppath, "dlls.txt"), sb.tostring)
this creates line each loaded dll in form key|value
, writes textfile. load again this:
if dlls nothing dlls = new dictionary(of string, string) dlls.clear() dim dllfile string = io.path.combine(application.startuppath, "dlls.txt") if io.file.exists(dllfile) = false exit sub dim loadeddlls() string = io.file.readalllines(dllfile) each s string in loadeddlls dim parts() string = strings.split(s, "|", 2) if parts.count <> 2 continue dlls.add(parts(0), parts(1)) next
this first loads lines file , generates string array them. iterates on lines , splits each line @ |
character maximum of 2 parts. adds part 0 key , part 1 value dictionary again.
Comments
Post a Comment