File splitting and merging
Public partial class form1: FORM {public form1 () {initializecomponent ();} // select the file event private void btn_selfile_click (Object sender, eventargs E) {string filter = "select file (*. *) | *. * "; openfileselection OFS = new openfileselection (filter, false); If (OFS. isfileselected () = true) {This. textbox1.text = ofs. getfilename ;}// select the directory event private void btn_seldir_click (Object sender, eventargs e) {directoryselecti On dirsel = new directoryselection (environment. specialfolder. desktop, "", true); If (dirsel. isdirectoryselected () = true) {This. textbox2.text = dirsel. getselectedpath ;}}// start to split private void btn_split_click (Object sender, eventargs e) {try {string fpath = This. textbox1.text; string splitdir = This. textbox2.text; splitfile (fpath, splitdir, 10); MessageBox. show ("split! "," Prompt ");} catch (exception ee) {MessageBox. show (EE. message, "prompt") ;}} public bool splitfile (string sourefilepath, string splitedstoredir, int filenums) {bool RBC = false; filestream FS = new filestream (sourefilepath, filemode. open); long filelength = FS. length; long fnum = (long) filenums; long filesize = filelength/fnum; For (INT I = 0; I <fnum; I ++) {int tmpfsize = (INT) filesize; string TMP Fname = (I + 1 ). tostring (); string tmpfpath = splitedstoredir + "\" + tmpfname; filestream WFS = new filestream (tmpfpath, filemode. openorcreate); byte [] array = NULL; if (I = fnum-1) {long len_pos = FS. length-fs.Position; array = new byte [len_pos]; FS. read (array, 0, (INT) len_pos); WFS. write (array, 0, (INT) len_pos);} else {array = new byte [tmpfsize]; FS. read (array, 0, tmpfsize); WFS. write (array, 0, tmpfsize);} WFS. flush (); WFS. close (); WFS. dispose (); WFS = NULL;} FS. close (); FS. dispose (); FS = NULL; return enumeration;} public bool unionfile (string splitedstoredir, string unionfilepath) {bool enumeration = false; string [] filepatharray = commonclass. getfiles (splitedstoredir, false); List <int> List = new list <int> (); foreach (string t in filepatharray) list. add (commonclass. tint (T. replace ("\", ""); L Ist. sort (); filestream WFS = new filestream (unionfilepath, filemode. append); For (INT I = 0; I <list. count; I ++) {string fp = splitedstoredir + "\" + list [I]. tostring (); filestream FS = new filestream (FP, filemode. open); byte [] dataarray = new byte [FS. length]; FS. read (dataarray, 0, (INT) FS. length); WFS. write (dataarray, 0, (INT) FS. length); // FS. close (); FS. dispose (); FS = NULL;} WFS. flush (); WFS. close (); WFS. dispose (); WFS = NULL; return rb;}// start merging private void btn_union_click (Object sender, eventargs e) {try {string splitdir = This. textbox2.text; unionfile (splitdir, splitdir + "\ union. ISO "); MessageBox. show ("merged! "," Prompt ");} catch (exception ee) {MessageBox. Show (EE. message," prompt ");}}}