c# - How do I build a path containing variables? -


i want create file directory, path contains 2 variables , error.

textwriter tw = new streamwriter(variable1+ "\" + variable2 + ".txt", true); tw.writeline(textbox.text); tw.close(); 

which correct format of path in streamwriter?

well you'll have got error because "\" isn't valid string literal.

however, you'd better off using path.combine - , file.appendalltext:

var file = path.combine(variable1, variable2 + ".txt"); file.appendalltext(file, textbox.text); 

note if did still want use writer, should use using statement file handle closed if exception thrown.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -