The process cannot access the file 'R:\mft classes\c# fundamental\c#.net apps\employee info\fileList.txt' because it is being used by another process -
i'm trying write file names in "filelist.txt".the file has been created when seek write in , shows me error above. should do?
string strfilepath; //the current path : "r:\mft classes\c# fundamental\c#.net apps\employeeinfo\windowsformsapplication2\bin\debug" strfilepath = directory.getcurrentdirectory(); strfilepath = directory.getparent(strfilepath).tostring(); strfilepath = directory.getparent(strfilepath).tostring(); strfilepath = directory.getparent(strfilepath).tostring(); strfilepath = strfilepath + "\\filelist.txt"; file.create(strfilepath); foreach (string saveme in listbox1.items) { file.writealltext(strfilepath, saveme); }
use stream author instead.
string strfilepath; //the current path : "r:\mft classes\c# fundamental\c#.net apps\employeeinfo\windowsformsapplication2\bin\debug" strfilepath = directory.getcurrentdirectory(); strfilepath = strfilepath + "\\filelist.txt"; using (streamwriter sw = new streamwriter(strfilepath, true)) { foreach (string saveme in listbox1.items) { sw.write(saveme); } }
c#
No comments:
Post a Comment