File creation in c# -
i working on small address book app, have make folder , inside folder .xml file, , problem app creates folder can't create file!
here code:
private void form1_load(object sender, eventargs e) { string path = environment.getfolderpath(environment.specialfolder.applicationdata); if(!directory.exists(path + "\\address book - neca")) directory.createdirectory(path + "\\ address book - neca"); if (!file.exists(path + "\\address book - neca//settings.xml")) file.create(path + "\\address book - neca//settings.xml"); }
i've improved code, take look. folder path has spaces between \
.
include:
using system.io;
and after:
private void form1_load(object sender, eventargs e) { // prepare path string path = environment.getfolderpath(environment.specialfolder.applicationdata); // prepare folder path string folderpath = path.combine(path, "address book - neca"); // prepare file path string settingfilepath = path.combine(folderpath, "settings.xml"); if(!directory.exists(folderpath)) directory.createdirectory(folderpath); if (!file.exists(settingfilepath)) file.create(settingfilepath); }
Comments
Post a Comment