i have created tcp server in c# receives file client , keeps in current directory. code segment follows:
using (filestream fstream = new filestream(path.getfilename(cmdfilename), filemode.create)) { fstream.write(buffer, 0, buffer.length); fstream.flush(); fstream.close(); } console.writeline("file received , saved in " + environment.currentdirectory);
where cmdfilename received filename.
now have created folder named "test" inside current directory using following code:
string root = environment.currentdirectory; string folder = path.combine(root,"test"); if (!directory.exists(folder)) directory.createdirectory(folder);
i want keep received file inside "test" folder. need make change following line of previous code segment:
using (filestream fstream = new filestream(path.getfilename(cmdfilename), filemode.create))
but change have make?
you using path.combine
path of new test
directory--you need use again find path of cmdfilename
file inside test
directory:
string cmdfilepath = path.combine(folder, path.getfilename(cmdfilename)); using (filestream fstream = new filestream(cmdfilepath, filemode.create))
Comments
Post a Comment