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

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -