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
Post a Comment