i have upload huge file using c# , mvc , here can able chunk big file several files using j-query slice(splitting files) function , uploaded server location. i'm not able open combined(merged) files again coded through c#.net.
mainly zip,.7z files not opened properly , rest of files .mp3, .doc,.pdf , etc opened in proper way.
here attached c# code
method 1:
private void joinfiles(string folderinputpath, string fileoutputpath) { directoryinfo disource = new directoryinfo(folderinputpath); filestream fssource = new filestream(fileoutputpath, filemode.append); foreach (fileinfo fipart in disource.getfiles(@"*.")) { byte[] bytepart = system.io.file.readallbytes(fipart.fullname); fssource.write(bytepart, 0, bytepart.length); } fssource.close(); } method 2:
{ string[] tmpfiles = directory.getfiles(server.mappath("~/app_data/uploads/tamp"), "*."); filestream outputfile = null; string prevfilename = ""; foreach (string tempfile in tmpfiles) { //string filename = path.getfilenamewithoutextension(tempfile); string basefilename = filename.substring(0, filename.indexof(convert.tochar("."))); string extension = path.getextension(filename); if (!prevfilename.equals(basefilename)) { if (outputfile != null) { outputfile.flush(); outputfile.close(); } outputfile = new filestream(server.mappath("~/app_data/uploads/tamp") + "\\" + basefilename + extension, filemode.openorcreate, fileaccess.write); } int bytesread = 0; byte[] buffer = new byte[1024]; filestream inputtempfile = new filestream(tempfile, filemode.openorcreate, fileaccess.read); while ((bytesread = inputtempfile.read(buffer, 0, 1024)) > 0) outputfile.write(buffer, 0, bytesread); inputtempfile.close(); system.io.file.delete(tempfile); prevfilename = basefilename; } outputfile.close(); }
Comments
Post a Comment