streamwriter - visual basic writing into files -


when want write file visual basic says cant becous in procces buts nothings else has op it. code.

imports system.io  public class form1     private sub button1_click(sender object, e eventargs) handles button1.click         button1.visible = false         label1.visible = false         pathlocation.visible = true         button2.visible = true     end sub      private sub label1_click(sender object, e eventargs) handles label1.click      end sub      private sub form1_load(sender object, e eventargs) handles mybase.load         pathlocation.visible = false         button2.visible = false     end sub      public sub button2_click(sender object, e eventargs) handles button2.click         dim path string         dim modsl string = "/modshop"         dim config string = "/config"         dim configfile string = "/config.txt"         dim configwriter system.io.streamwriter         path = pathlocation.text         path = path + modsl         my.computer.filesystem.createdirectory(path)         config = path + config         my.computer.filesystem.createdirectory(config)         configfile = config + configfile         file.create(configfile)         configwriter = file.appendtext(configfile)         configwriter.write(path)         configwriter.close()         button2.visible = false      end sub      private sub pathlocation_textchanged(sender object, e eventargs) handles pathlocation.textchanged      end sub end class 

file.create creates file , returns filestream, following file.appendtext finds file opened , fails

you simplify lot code considering , fact directory.createdirectory method builds missing directories in path passed

dim path = system.io.path.combine(pathlocation.text, "modshop") dim fullpath = system.io.path.combine(path, "config") directory.createdirectory(fullpath) dim configfile = system.io.path.combine(fullpath, "config.txt") file.writealltext(configfile, path) 

following logic of code have used file.writealltext creates or overwrite configfile if exists. if want append existing file without overwriting contents use file.appendalltext


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -