.net - How to create file with variables in file path? -


i new visual basic , i'm trying create file code

private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click     dim curboard string = comboard.selecteditem     dim curstd string = comstd.selecteditem     dim curdiv string = comdiv.selecteditem     dim curmed string = commed.selecteditem     dim filepath string = "c:\program files\school attandance management system 1.0\data\" & curdiv & ".samsclass"      try         file.create(filepath)     catch ex exception         messagebox.show(ex.message)     end try   end sub 

this outputs

illigal characters in path

comdiv,comstd,commed , comboard comboboxes please let me know how concatenete variables filepath ?

to concatenate strings form valid file paths should use path class , method path.combine

path.combine("c:\program files\school attandance management system 1.0\data",               curdiv, ".samsclass") 

notice how method accepts array of strings , combine them form valid file path inserting correct path separator needed.

of course variable curdiv should not contains invalid filename characters ones can obtain method getinvalidfilenamechars

you try remove invalid chars code this, correct approach should not allow invalid names in combobox

dim invalidfilechars() char = path.getinvalidfilenamechars() each c in invalidfilechars     curdiv = curdiv.replace(c.tostring(), "") next 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -